Hello there!
I am trying to make two count down timers on LCD keypad shield.
The idea is when the first timer goes to 00:00 (MM:SS), the second one to start counting. I have made something so far. But there is a problem. When the first timer goes to 00:01 the second timer starts to count, i do not know what i have mistaken.
I am pretty shure the code can be made to look a lot more “elegant”.
Please assist me.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int a;
int b;
int c;
int d;
void setup() {
lcd.begin(16, 2);
lcd.print("Timer 1");
lcd.setCursor(9,0);
lcd.print("Timer 2");
lcd.setCursor(2,1);
lcd.print(":");
a=0; //minuti TMR1:
b=10; //sekundiTMR1:
c=10; //minuti TMR2:
d=20; //sekundi TMR2:
lcd.setCursor(0,1);
lcd.print(a);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(3,1);
lcd.print(b);
lcd.setCursor(11,1);
lcd.print(c);
lcd.setCursor(13,1);
lcd.print(":");
lcd.setCursor(14,1);
lcd.print(d);
}
void loop() {
if (a>20)
{
a=20;
}
if (a>0 || b>0)
{
if (a>=10)
{
lcd.setCursor(0,1);
lcd.print(a);
}
else
{
lcd.setCursor(0,1);
lcd.print("0");
lcd.setCursor(1,1);
lcd.print(a);
}
if (b>=10)
{
lcd.setCursor(3,1);
lcd.print(b);
}
else
{
lcd.setCursor(3,1);
lcd.print("0");
lcd.setCursor(4,1);
lcd.print(b);
}
if (b==0)
{
b=60;
a--;
}
b--;
}
else
{
lcd.setCursor(0,1);
lcd.print("00:00");
}
if (a==0 && b==0)
{
d--;
if (d>=10)
{
lcd.setCursor(14,1);
lcd.print(d);
}
else
{
lcd.setCursor(14,1);
lcd.print("0");
lcd.setCursor(15,1);
lcd.print(d);
}
if (d==0)
{
c--;
d=60;
}
if (a>=10)
{
lcd.setCursor(11,1);
lcd.print(a);
}
else
{
lcd.setCursor(11,1);
lcd.print("0");
lcd.setCursor(12,1);
lcd.print(a);
}
}
delay(1000);
}