#include <time.h>
#include "my_lcd.h"
MyLCD lcd;
void setup() {
Serial.begin(115200);
lcd.begin();
struct tm timeinfo;
timeinfo.tm_year = 2025 - 1900; // Years since 1900
timeinfo.tm_mon = 4; // 0 = January, so 4 = May
timeinfo.tm_mday = 26;
timeinfo.tm_hour = 12;
timeinfo.tm_min = 0;
timeinfo.tm_sec = 0;
time_t t = mktime(&timeinfo);
struct timeval now = { .tv_sec = t, .tv_usec = 0 };
settimeofday(&now, NULL);
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
// Convert to 12-hour format
int hour12 = timeinfo.tm_hour % 12;
if (hour12 == 0) hour12 = 12;
const char* am_pm = (timeinfo.tm_hour >= 12) ? "PM" : "AM";
// Format the datetime string
char buffer[21];
snprintf(buffer, sizeof(buffer), "%02d-%02d-%04d %02d:%02d %s",
timeinfo.tm_mday,
timeinfo.tm_mon + 1,
timeinfo.tm_year + 1900,
hour12,
timeinfo.tm_min,
am_pm);
lcd.display("ESP32-DevKitC-v4", "Hello Kitty!", "Ninja Escape Plan..");
delay(5000);
lcd.clear();
lcd.datetime(buffer);
lcd.alarm(1, "Temp UL1:", "40.6", 0);
delay(5000);
lcd.alarm(2, "Curr UL2:", "60.0", "A");
delay(5000);
}