The schematic diagram is more than simple. Just connect 5 or more green LEDs on ports 0-7 and one red LED on port 8.
Here is photo of my assembled board.
Is it possible to make the code shorter?!
/*
Arduino - count down timer
*/
int MAX_LEDS = 5; // max_leds = maximun minutes
int counter = 60 * MAX_LEDS;
bool flip_flop = LOW;
void setup() {
DDRB = DDRC = DDRD = 255; // set all ports to output
PORTD = (((unsigned int)1 << MAX_LEDS) - 1); // ON first N LEDs
while(counter--){
delay(1000); // wait for a second
flip_flop = flip_flop == LOW ? HIGH : LOW;
digitalWrite((int)(counter/60), flip_flop); // blink current minute LED
}
while(true){
delay(1000); // wait for a second
flip_flop = flip_flop == LOW ? HIGH : LOW;
digitalWrite(8, flip_flop); // blink red light
}
}
void loop() {
}
and video
Enjoy!
No comments:
Post a Comment