//結構先用出來(0~9),再慢慢加功能
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 KeyData1, KeyData2;
int num = 0;
int delaytime = 500;
int sw1 = 9;
int sw2 = 10;
void setup()
{
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
for (i = 0; i < 7; i++)
{
pinMode(seg7[i], OUTPUT);
}
}
void loop()
{
KeyData1 = digitalRead(sw1);
KeyData2 = digitalRead(sw2);
if (KeyData1 == LOW)
{
delay(20);
while (digitalRead(sw1) == LOW);
num++;
if (num == 10)num = 0;
}
if (KeyData2 == LOW)
{
delay(20);
while (digitalRead(sw2) == LOW);
num--;
if (num < 0)num = 9;
}
out(~table[num]);
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;
}
}
沒有留言:
張貼留言