#include <RTClib.h> // Define RTC_DS1307 and DateTime
#include "my_lcd.h"
MyLCD lcd;
RTC_DS1307 rtc;
void setup() {
Serial.begin(115200);
lcd.begin();
if (!rtc.begin()) { // Time is critial
Serial.println(F("Error: RTC not found!"));
while (1); // Halt if RTC fails
}
}
void loop() {
lcd.display("ESP32-DevKitC-v4", "Hello, World!", "Ngee Ann Poly");
delay(5000);
lcd.clear();
DateTime now = rtc.now();
char dtbuf[21] = "YYYY-MM-DD hh:mm:ss";
now.toString(dtbuf); // Formats time into dtbuf
lcd.datetime(dtbuf);
lcd.alarm(1, "Temp UL1:", "40.6", 0);
delay(5000);
lcd.alarm(2, "Curr UL2:", "60.0", "A");
delay(5000);
}
/*
// Test DateTime constructors
{
DateTime dt(2025, 5, 29, 9, 15, 21); // 2025-5-29 09:15:21
memcpy(dtbuf, TIME_FORMAT, sizeof(TIME_FORMAT)); // Reset format
Serial.println(dt.toString(dtbuf));
}
{
DateTime dt(__DATE__, __TIME__); // Code compilation date/time
memcpy(dtbuf, TIME_FORMAT, sizeof(TIME_FORMAT)); // Reset format
Serial.println(dt.toString(dtbuf));
}
{
DateTime dt("2000-01-01T00:00:00Z"); // ISO 8601 date string
memcpy(dtbuf, TIME_FORMAT, sizeof(TIME_FORMAT)); // Reset format
Serial.println(dt.toString(dtbuf));
}
{
DateTime dt(1234567); // seconds since 2000
memcpy(dtbuf, TIME_FORMAT, sizeof(TIME_FORMAT)); // Reset format
Serial.println(dt.toString(dtbuf));
}
*/LCD (20x4) (I2C)
DS1307 RTC