I've been working to make an Arduino countdown timer. A 16x2 display is wired up, but now I just need to get the coding right.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 13, 11, 10, 9, 8); //Pins used for display
signed short minutes, seconds;
char timeline[16];
void setup() {
lcd.begin(16, 2); //Start cursor setting
lcd.print("Time Remaining:"); //Top bar message
}
void loop() {
lcd.setCursor(0, 1);
sprintf(timeline,"%0.2d:%0.2d secs", minutes, seconds);
lcd.print(timeline);
delay(1000);
seconds--;
if (minutes > 0 || seconds > 0); { // count down
if (--seconds < 0) {
seconds = 59;
--minutes;
}
}
}
My current issue is that it is counting up. Instead, I need it to count down starting at 45 minutes and 00 seconds and for the timer to stop once it has reached 00:00.
if (minutes > 0 && seconds > 0) // count down
. Alsoif (--seconds < 0) { seconds = 59; --minutes; }
. And at last you should initialize minutes and seconds to something. – KIIVif (minutes > 0 || seconds > 0)
– KIIV