步驟1:
我使用帶有Arduino的Darlington ULN2803來控制Evil Mad Scientist的巨型共陽極7段顯示器。
正常尺寸的7段顯示器由7個矩形LED組成,這些LED排列成可以顯示數字0-9。點亮正常的7段顯示器的一部分相當于點亮LED,它需要大約3V和20mA的電流;僅由Arduino即可輕松實現。這個巨大的7段有點不同,因為每個段都由4組并聯的15組紅色LED線串聯而成(圖2)。要打開LED,段上的電壓應為15 *(每個LED的正向電壓),流過每個段的電流為4 *(每個LED的典型工作電流)。每節輸出約為31.5V(15 * 2.1V)和80mA(4 * 20mA),顯然Arduino將無法自行處理。
要控制此顯示,我連接了共陽極到36V,然后選擇性地將要點亮的顯示器各部分接地。
下面的代碼通過7段顯示器上的數字0-9進行計數,每秒從一個數字滴答到另一個。它使用for循環將變量“ i”從0-9遞增,然后使用switch/case語句打開相應的段(通過將其相應的Arduino引腳設置為高電平。
/*7 seg display with ULN2803
by RU4Realz
July 2012
arduino pin connections (via ULN2803):
arduino (digital) pin 0 7 seg pin f
1 g
2 a
3 b
4 c
5 d
6 e
*/
void setup() {
for (byte a=0;a《8;a++){
pinMode(a,OUTPUT);//set digital pins 0 - 6 as outputs
}
}
void loop() {
for (byte i = 0; i 《 10; i++){//for 0 -9
switch(i){
case 0://if i == 0, turn on appropriate leds
PORTD&=128;//turn digital 0-6 off
digitalWrite(0,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
break;
case 1://if i == 1
PORTD&=128;//turn digital 0-6 off
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
break;
case 2://if i == 2
PORTD&=128;//turn digital 0-6 off
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
break;
case 3:
PORTD&=128;
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
break;
case 4:
PORTD&=128;//turn digital 0-7 off
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
break;
case 5:
PORTD&=128;//turn digital 0-7 off
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
break;
case 6:
PORTD&=128;//turn digital 0-7 off
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
break;
case 7:
PORTD&=128;//turn digital 0-7 off
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
break;
case 8:
PORTD&=128;//turn digital 0-7 off
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
break;
case 9:
PORTD&=128;//turn digital 0-7 off
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
break;
}
delay (1000);//wait 1 sec
}
}
-
功率電路
+關注
關注
0文章
29瀏覽量
14551 -
Arduino
+關注
關注
188文章
6469瀏覽量
187077 -
ULN2803
+關注
關注
5文章
23瀏覽量
18828
發布評論請先 登錄
相關推薦
評論