int seg7[] = { 2, 3, 4, 5, 6, 7, 8};
int table[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
int i, j;
int delaytime = 500;
void setup()
{
// put your setup code here, to run once:
for (i = 0; i < 7; i++)
{
pinMode(seg7[i], OUTPUT);
}
}
void loop()
{
// put your main code here, to run repeatedly:
for (i = 0; i < 10; i++)
{
out(~table[i]); delay(delaytime);//我的板子是共陰極+npn電晶體
}
}
void out(byte data)
{
for (j = 0; j < 7; j++)
{
if (data % 2 == 1)
digitalWrite(seg7[j], HIGH);//共陰極,1亮
else
digitalWrite(seg7[j], LOW);
data = data / 2;
}
}
沒有留言:
張貼留言