char seg7Table1[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
char lineTable2[] = {0x81, 0x00, 0x00, 0x00, 0x00, 0x88, 0x90, 0xa0};char lineTable3[] = {0x00, 0x81, 0x82, 0x84, 0x88, 0x00, 0x00, 0x00};
char seg7Pin[] = {2, 3, 4, 5, 6, 7, 8};
char comPin[] = {9, 10, 11, 12};
char sw1 = 14;
char sw2 = 15;
int number1;
int number2;
int counter1 = 0;
int counter2 = 0;
int add1 = 1;
int add2 = 1;
unsigned long time = 0;
int i;
int j;
void setup()
{
int i;
for (i = 0; i < 7; i++)
{
pinMode(seg7Pin[i], OUTPUT);
// digitalWrite(seg7Pin[i], LOW);
}
for (i = 0; i < 4; i++)
{
pinMode(comPin[i], OUTPUT);
digitalWrite(comPin[i], LOW);
}
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
}
void loop()
{
char val1 = digitalRead(sw1);
if (val1 == 0)
{
delay(20);
while (digitalRead(sw1) == LOW);
add1++;
}
//========================================
char val2 = digitalRead(sw2);
if (val2 == 0)
{
delay(20);
while (digitalRead(sw2) == LOW);
add2++;
}
//========================================
number1 = counter1;
for (j = 0; j < 7; j++)//先秀出個位數
{
if (bitRead(~seg7Table1[number1 % 10], j))
digitalWrite(seg7Pin[j], HIGH);
else
digitalWrite(seg7Pin[j], LOW);
}
digitalWrite(comPin[0], HIGH); delay(5);
digitalWrite(comPin[0], LOW);
number1 = number1 / 10;//除10秀出十位數
for (j = 0; j < 7; j++)
{
if (bitRead(~seg7Table1[number1 % 10], j))
digitalWrite(seg7Pin[j], HIGH);
else
digitalWrite(seg7Pin[j], LOW);
}
digitalWrite(comPin[1], HIGH); delay(5);
digitalWrite(comPin[1], LOW);
if (millis() - time >= 1000)
{
time = millis();
if (add1 % 2 == 1 )
{
counter1++;
if (counter1 > 99)counter1 = 0;
}
else
{
counter1--;
if (counter1 < 0)counter1 = 99;
}
}
//=================================================
number2 = counter2;
for (j = 0; j < 7; j++)
{
if (bitRead(lineTable2[number2 % 8], j))
digitalWrite(seg7Pin[j], HIGH);
else
digitalWrite(seg7Pin[j], LOW);
}
digitalWrite(comPin[3], HIGH); delay(5);
digitalWrite(comPin[3], LOW);
for (j = 0; j < 7; j++)
{
if (bitRead(lineTable3[number2 % 8], j))
digitalWrite(seg7Pin[j], HIGH);
else
digitalWrite(seg7Pin[j], LOW);
}
digitalWrite(comPin[2], HIGH); delay(5);
digitalWrite(comPin[2], LOW);
if (millis() - time >= 1000)
{
time = millis();
if (add2 % 2 == 1 )
{
counter2++;
if (counter2 > 7)counter2 = 0;
}
else
{
counter2--;
if (counter2 < 0)counter2 = 7;
}
}
}
沒有留言:
張貼留言