int seg7[] = {2, 3, 4, 5, 6, 7, 8};
int table7seg[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
int com[] = {9, 10, 11, 12};
int i, j;
int sw = 13;
unsigned long time = 0;
int count ;
void disp2020()
{
int i, j;
for (i = 0; i < 50; i++)
{
for (j = 0; j < 7; j++)
{
if (bitRead(~table7seg[0], j))//0
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
delay(1); digitalWrite(9, LOW);//關閉鬼影
for (j = 0; j < 7; j++)
{
if (bitRead(~table7seg[2], j))//2
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(9, LOW );
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
delay(1); digitalWrite(10, LOW);
for (j = 0; j < 7; j++)
{
if (bitRead(~table7seg[0], j))//0
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(9, LOW);
digitalWrite(10, LOW );
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
delay(1); digitalWrite(11, LOW);
for (j = 0; j < 7; j++)
{
if (bitRead(~table7seg[2], j))//2
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW );
digitalWrite(12, HIGH);
delay(1); digitalWrite(12, LOW);
}
}
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);
for (j = 0; j < 3; j++)//跑閃爍三次2020
{
disp2020();
for (i = 9; i < 13; i++)
{
digitalWrite(com[i], LOW);
}
delay(500);
}
delay(2000);
}
void loop()
{
int add;
int number;
if (digitalRead(sw) == LOW)
{
delay(20);
while (digitalRead(sw) == LOW);
add++;
}
number = count;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 7; j++)
{
if (bitRead(~table7seg[number % 10], j))
{
digitalWrite(seg7[j], HIGH);
}
else
{
digitalWrite(seg7[j], LOW);
}
}
digitalWrite(com[i], HIGH);
delay(5);
digitalWrite(com[i], LOW);
number = number / 10;
if (millis() - time >= 1000)
{
time = millis();
if (add % 2 == 0)
{
count++;
if (count > 99)count = 0;
}
else
{
count--;
if (count < 0)count = 99;
}
}
}
}
沒有留言:
張貼留言