int seg7[] = {2, 3, 4, 5, 6, 7, 8};
int table7seg[] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xFF};
int com[] = {9, 10, 11, 12};
int i, j;
int sw = 13;
unsigned long time = 0;
int count ;
void setup()
{
for (i = 0; i < 8; i++)
{
pinMode(seg7[i], OUTPUT);
}
for (i = 0; i < 4; i++)
{
pinMode(com[i], OUTPUT);
}
pinMode(sw, INPUT);
}
void loop()
{
int add;
int number;
if (digitalRead(sw) == LOW)
{
delay(20);
while (digitalRead(sw) == LOW);
add++;
}
number = count;
for (i = 0; i < 1; i++)
{
for(j=0;j<6;j++)//一個七段index 從0跑到5
{
if (bitRead(~table7seg[number], j))
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(com[i], HIGH);
delay(5);
digitalWrite(com[i], LOW);
if (millis() - time >= 1000)
{
time = millis();
if (add % 2 == 0)
{
count++;
if (count > 5)count = 0;//超過5要歸0
}
else
{
count--;
if (count < 0)count = 5;//小於0要歸5
}
}
}
}
沒有留言:
張貼留言