Hello,
I am trying to design a 60 second count down timer. I want the timer to start when push button is pressed. When the timer is done I want a idle message until the same push button is pressed.
I have the timer counting down but when it reaches 0 it jumps to a trigger to display "Game Over". Currently I have it programmed to "loop()" after a delay because I am just trying to get it to reset. When it loops all it does is display the "Count Down Timer" line but it doesn't start timing or counting down
I am ignoring the push button part right now and focusing on getting the timer to self reset after a delay
#include <LiquidCrystal.h>
// Goal; 60 second count down timer, when reaches 0 display "Game over"
// Continue displaying "Game Over" until start button is pressed to reset
int hours = 0; // start hours
int minutes = 0; //start min
int seconds = 60; //start seconds
//#define startbutton 7 // start button on pin 7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //<--removed- Different LCD manufacture
void setup() {
//pinMode (startbutton, INPUT_PULLUP); //
// digitalWrite (startbutton, LOW);
}
void loop() {
lcd.begin(16, 2);
lcd.print("Count Down Timer ");
// lcd.scrollDisplayLeft();
// wait a bit:
delay(2000);
while (hours > 0 || minutes > 0 || seconds >= 0) {
lcd.setCursor(4, 2);
(hours < 10) ? lcd.print("0") : NULL;
lcd.print(hours);
lcd.print(":");
(minutes < 10) ? lcd.print("0") : NULL;
lcd.print(minutes);
lcd.print(":");
(seconds < 10) ? lcd.print("0") : NULL;
lcd.print(seconds);
lcd.display();
stepDown();
delay(1000);
}
}
void stepDown() {
if (seconds > 0) {
seconds -= 1;
} else {
if (minutes > 0) {
seconds = 59;
minutes -= 1;
} else {
if (hours > 0) {
seconds = 59;
minutes = 59;
hours -= 1;
} else {
trigger();
}
}
}
}
void trigger() {
lcd.clear(); // clears the screen and buffer
lcd.setCursor(0, 1); // set timer position on lcd for end.
lcd.println("GAME OVER ");
delay(1000);
loop(); // restart timer
//if (startbutton == HIGH) {
//// if start button pressed, reset timer
//loop();
}
//}