#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TimeLib.h>
// #include <DS3232RTC.h>
#include <DS1307RTC.h>
tmElements_t tm;
#define but1 17
#define LCD 0x27
LiquidCrystal_I2C lcd(LCD,16,2);
//DS3232RTC RTC;
uint32_t btnTimer = 0;
void setup() {
pinMode(but1 , INPUT_PULLUP);
lcd.init();
lcd.backlight();
//RTC.begin();
if (RTC.read(tm)) {
setTime(tm.Hour,tm.Minute,tm.Second,tm.Day,tm.Month,tm.Year-30);
}
}
void loop() {
bool btnState = !digitalRead(but1);
if (btnState && millis() - btnTimer > 100) {
btnTimer = millis();
RTCset();
}
time_lcd();
lcd.setCursor(0, 0);
lcd.print(timeStatus());
}
void RTCset(){
tm.Hour++;
if (RTC.write(tm)) {
setTime(tm.Hour,tm.Minute,tm.Second,tm.Day,tm.Month,tm.Year);
}
}
void RTCread(){
if (RTC.read(tm)) {
tm.Day;
tm.Month;
tm.Year;
tm.Hour;
tm.Minute;
tm.Second;
}
}
void time_lcd(){
lcd.setCursor(11, 0);
if (hour() < 10)
lcd.print(" ");
lcd.print(hour());
lcd.print(":");
printDigits(minute());
//lcd.print(" ");
lcd.setCursor(6, 1);
printDigits(day());
lcd.print(".");
printDigits(month());
lcd.print(".");
lcd.print(year());
}
void printDigits(int digits)
{
if (digits < 10)
lcd.print("0");
lcd.print(digits);
}