#include <LiquidCrystal_I2C.h>
#include "Clock.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
Clock rtc;
bool changeHrs, changeMins;
int pressCnt;
void setup() {
rtc.begin();
lcd.init();
lcd.backlight();
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void loop() {
DateTime time = rtc.now();
int hr = time.hour();
int min_ = time.minute();
int sec = time.second();
if (millis() > 30000)
{
lcd.noBacklight();
}
if (!analogRead(A0))
{
pressCnt++;
}
switch (pressCnt)
{
case 0:
lcd.setCursor(0, 1);
lcd.println(" ");
changeHrs, changeMins = false;
break;
case 1:
lcd.setCursor(0, 1);
lcd.println("hr ");
changeHrs = true;
changeMins = false;
break;
case 2:
lcd.setCursor(0, 1);
lcd.println("min");
changeHrs = false;
changeMins = true;
break;
case 3:
pressCnt = 0;
break;
}
if (hr == 60)
{
hr = 0;
}
else if (min_ == 60)
{
min_ = 0;
}
else if (sec == 60)
{
sec = 0;
}
lcd.home();
if (hr < 10)
{
lcd.print(String("0") + hr + String(":"));
}
else
{
lcd.print(hr + String(":"));
}
lcd.setCursor(3, 0);
if (min_ < 10)
{
lcd.print(String("0") + min_ + String(":"));
}
else
{
lcd.print(min_ + String(":"));
}
lcd.setCursor(6, 0);
if (sec < 10)
{
lcd.print(String("0") + sec);
}
else
{
lcd.print(sec);
}
}