本帖最后由 大连林海 于 2016-2-24 15:18 编辑
最近收到好好搭搭送的一套Arduino的小产品,里面有nano的主控和一些电阻和数码管及常用的工具,看到网上很多数码管的教程,一直没有玩过面包板,就跟随网上的大神做一个arduino、面包板、数码管的实验。用来显示几个简单的数字。使用的代码单位时间只亮一个数码管上的灯,肉眼看到的1,2,3是因为高刷新率,大于肉眼分辨速度,使得肉眼看到1,2,3等。这样的好处是亮度高,而且亮度均匀。
所用器材:
面包板一个
DFRduino*1
数码管*1
杜邦线若干

连线图:
发现自己手里没有那么多针脚的杜邦线 于是乎 我就用工具把一头减掉 去皮 露出电源金属部分 直接插到面包板上,哈哈
    
代码如下
-
-
- void setup() {
-
- pinMode(13,OUTPUT);
-
- for(int n=2;n<=9;n++)
- {
- pinMode(n,OUTPUT);
- }
- }
-
-
- void loop()
- {
-
- digitalWrite(13,1);
-
-
- /*==========显示0=============*/
- int n0[8]={0,0,0,0,0,0,1,1};
- int z=0;
- for(int x=2;x<=9;x++)
- {
- digitalWrite(x,n0[z]);
- z++;
- if (z>=9)
- z=0;
- }
- delay(1000);
- /*==========显示1=============*/
- int n1[8]={1,0,0,1,1,1,1,1};
- z=0;
- for(int x=2;x<=9;x++)
- {
- digitalWrite(x,n1[z]);
- z++;
- if (z>=9)
- z=0;
- }
- delay(1000);
- /*==========显示2=============*/
- int n2[8]={0,0,1,0,0,1,0,1};
- z=0;
- for(int x=2;x<=9;x++)
- {
- digitalWrite(x,n2[z]);
- z++;
- if (z>=9)
- z=0;
- }
- delay(1000);
- /*==========显示3=============*/
- int n3[8]={0,0,0,0,1,1,0,1};
- z=0;
- for(int x=2;x<=9;x++)
- {
- digitalWrite(x,n3[z]);
- z++;
- if (z>=9)
- z=0;
- }
- delay(1000);
- /*==========显示4=============*/
- int n4[8]={1,0,0,1,1,0,0,1};
- z=0;
- for(int x=2;x<=9;x++)
- {
- digitalWrite(x,n4[z]);
- z++;
- if (z>=9)
- z=0;
- }
- delay(1000);
- }
复制代码
PS:
但是我发现 最后效果不同,总是有些不同 这是为什么呢?大神指教 ,看看我的连线是否有问题
file:///c:/users/admin/appdata/roaming/360se6/User Data/temp/201833d2e6uvphchm65xr8.jpg
|