int seg7_pin[] = {2, 3, 4, 5, 6, 7, 8};
int seg7_table[] = {~0xc0, ~0xf9, ~0xa4, ~0xb0, ~0x99, ~0x92, ~0x82, ~0xf8, ~0x80, ~0x90};
int delaytime = 1000;
int btn_pin = 9;
int num_val;
int cnt_val;
int even_odd;
void setup()
{
pinMode(btn_pin, INPUT);
for (int i = 0; i < 7; i++)
{
pinMode(seg7_pin[i], OUTPUT);
digitalWrite(seg7_pin[i], LOW);
}
}
//-------------------------------
void outport(byte data)
{
for (int j = 0; j < 7; j++)
{
if (data % 2 == 1)
digitalWrite(seg7_pin[j], HIGH);
else
digitalWrite(seg7_pin[j], LOW);
data = data / 2;
}
}
void loop() {
num_val = digitalRead(btn_pin);
if (num_val == 0)
{
while (digitalRead(btn_pin) == LOW)
{
even_odd++;
}
}
if (even_odd % 2 == 0)
{
if (cnt_val == 9)
cnt_val = 0;
else
cnt_val++;
}
else
{
if (cnt_val == 0)
cnt_val = 9;
else
cnt_val--;
}
outport(seg7_table[cnt_val]);
delay(delaytime);
}
沒有留言:
張貼留言