步驟1:
我使用帶有Arduino的Darlington ULN2803來控制Evil Mad Scientist的巨型共陽極7段顯示器。
正常尺寸的7段顯示器由7個矩形LED組成,這些LED排列成可以顯示數(shù)字0-9。點亮正常的7段顯示器的一部分相當于點亮LED,它需要大約3V和20mA的電流;僅由Arduino即可輕松實現(xiàn)。這個巨大的7段有點不同,因為每個段都由4組并聯(lián)的15組紅色LED線串聯(lián)而成(圖2)。要打開LED,段上的電壓應(yīng)為15 *(每個LED的正向電壓),流過每個段的電流為4 *(每個LED的典型工作電流)。每節(jié)輸出約為31.5V(15 * 2.1V)和80mA(4 * 20mA),顯然Arduino將無法自行處理。
要控制此顯示,我連接了共陽極到36V,然后選擇性地將要點亮的顯示器各部分接地。
下面的代碼通過7段顯示器上的數(shù)字0-9進行計數(shù),每秒從一個數(shù)字滴答到另一個。它使用for循環(huán)將變量“ i”從0-9遞增,然后使用switch/case語句打開相應(yīng)的段(通過將其相應(yīng)的Arduino引腳設(shè)置為高電平。
/*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
}
}
-
功率電路
+關(guān)注
關(guān)注
0文章
29瀏覽量
14536 -
Arduino
+關(guān)注
關(guān)注
187文章
6457瀏覽量
186502 -
ULN2803
+關(guān)注
關(guān)注
5文章
23瀏覽量
18801
發(fā)布評論請先 登錄
相關(guān)推薦
評論