#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup () {
Serial.begin(9600);
// Check if the RTC is connected
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
lcd.init();
lcd.clear();
}
void loop () {
DateTime now = rtc.now();
String time = addLeftZero(now.hour()) + ":" + addLeftZero(now.hour());
lcd.print("Current time:");
lcd.setCursor(0, 1);
lcd.print(time);
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
}
String addLeftZero(int value) {
if (value < 10) {
return "0"+String(value);
}
return String(value);
}