极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12064|回复: 2

自制最小系统驱动数码管

[复制链接]
发表于 2012-11-23 23:23:35 | 显示全部楼层 |阅读模式
接线方法见强哥教程http://www.geek-workshop.com/thread-2038-1-1.html
强哥写的代码不敢恭维,哈哈哈,我自己又整理了份 重新传下吧。
  1. void setup() {  
  2.     pinMode(13,OUTPUT);         
  3.     for(int n=2;n<=9;n++) {
  4.      pinMode(n,OUTPUT);
  5.    }
  6. }
  7. byte numbers[10][8] = {
  8.   {0,0,0,0,0,0,1,1},  // = 0
  9.   {1,0,0,1,1,1,1,1},  // = 1
  10.   {0,0,1,0,0,1,0,1},  // = 2
  11.   {0,0,0,0,1,1,0,1},  // = 3
  12.   {1,0,0,1,1,0,0,1},  // = 4
  13.   {0,1,0,0,1,0,0,1},  // = 5
  14.   {0,1,0,0,0,0,0,1},  // = 6
  15.   {0,0,0,1,1,1,1,1},  // = 7
  16.   {0,0,0,0,0,0,0,1},  // = 8
  17.   {0,0,0,0,1,0,0,1}   // = 9
  18.   };   
  19. int index=0;
  20. void loop()
  21. {
  22. digitalWrite(13,1);
  23. show();
  24. index++;
  25. if(index>9)index=0;
  26.   delay(1000);

  27. }
  28. void show(){
  29.   int x=2;
  30.   for(int z=0;z<8;z++)      
  31.   {
  32.     digitalWrite(x,numbers[index][z]);      
  33.     x++;
  34.   }
  35. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2012-11-24 16:38:44 | 显示全部楼层
这个好,代码真整洁,支持一下
回复 支持 反对

使用道具 举报

发表于 2012-12-23 14:03:37 | 显示全部楼层
这个show()函数最好带个参数,方便一般调用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-11 00:45 , Processed in 0.041884 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表