Hi,
I`m building a countdown timer with a LED segment display that counts down from 9 to 0. It also makes a beep on each count on a speaker...
I´m having trouble with the code, though. A switch is to trigger this event. If I press the switch now, it all starts, but I can´t stop it with unpressing the switch. What causes this ?
Heres the code:
#define input 10
void setup()
{
pinMode(11,LOW);
pinMode(8,HIGH);
pinMode(7,HIGH);
pinMode(6,HIGH);
pinMode(5,HIGH);
pinMode(4,HIGH);
pinMode(3,HIGH);
pinMode(2,HIGH);
pinMode(1,HIGH);
pinMode(0,HIGH);
}
void loop()
{
if
(digitalRead(input))
{delay(1000);
PORTD=0b10011000; // 9
tone(8, 440, 200);
delay(1000);
PORTD=0b10000000; // 8
tone(8, 440, 200);
delay(1000);
PORTD=0b11111000; // 7
tone(8, 440, 200);
delay(1000);
PORTD=0b10000010; // 6
tone(8, 440, 200);
delay(1000);
PORTD=0b10010010; // 5
tone(8, 440, 200);
delay(1000);
PORTD=0b10011001; // 4
tone(8, 440, 200);
delay(1000);
PORTD=0b10110000; // 3
tone(8, 440, 200);
delay(1000);
PORTD=0b10100100; // 2
tone(8, 440, 200);
delay(1000);
PORTD=0b11111001; // 1
tone(8, 440, 200);
delay(1000);
PORTD=0b11000000; // 0
tone(8, 980, 30000);
delay(30300);}
else
{
}
}