// LCD #include #include #include // NTP #include #include const char* ssid = "........"; const char* password = "........"; const String DAY[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; LiquidCrystal_I2C lcd(0x27, 16, 2); //address, columns, rows BigFont02_I2C big(&lcd); // construct large font object, passing to it the name of our lcd object void setup() { // NTP Serial.begin(115200); Serial.setDebugOutput(true); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println("\nConnecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(1000); } configTime(10 * 3600, 0, "pool.ntp.org", "time.nist.gov"); // UTC + 10, no DST Serial.println("\nWaiting for time"); while (!time(nullptr)) { Serial.print("."); delay(1000); } Serial.println(""); // LCD lcd.begin(); big.begin(); lcd.clear(); lcd.setCursor(0,1); lcd.write (' BigFont02_I2C '); lcd.setCursor(0,1); lcd.write (' ============= '); delay(2000); lcd.clear(); } void loop() { // NTP time_t now = time(nullptr); Serial.println(ctime(&now)); // DATE lcd.clear(); struct tm *ptm = localtime(&now); int weekday = ptm->tm_wday; lcd.setCursor(0,1); lcd.print(DAY[weekday]); // 0..6 -> Sun..Sat big.writeint(0,3 ,ptm->tm_mday ,2,true); //display day of the month (1-31) value using 2 digits with leading zeros enabled starting at row 0 column 3 big.writeint(0,10,ptm->tm_mon + 1 ,2,true); //display month (0-11) value using 2 digits with leading zeros enabled starting at row 0 column 10 delay(3000); // TIME lcd.clear(); big.writeint(0,7,ptm->tm_min ,2,true); // 00..59 lcd.setCursor(6,1); lcd.print("."); lcd.setCursor(6,0); lcd.print("."); if ( ptm->tm_hour == 0 ) { lcd.setCursor(14,0); lcd.print("AM"); big.writeint(0,0,12,2,false); // 0:00 to 0:59 -> 12:00 AM to 12:59 AM } if (( ptm->tm_hour != 0 ) && ( ptm->tm_hour < 12 )) { lcd.setCursor(14,0); lcd.print("AM"); big.writeint(0,0,ptm->tm_hour,2,false); // 1:00 to 11:59 -> 1:00 AM to 11:59 AM } if ( ptm->tm_hour == 12 ) { lcd.setCursor(14,0); lcd.print("PM"); big.writeint(0,0,ptm->tm_hour,2,false); // 12:00 to 12:59 -> 12:00 PM to 12:59 PM } if ( ptm->tm_hour > 12 ) { lcd.setCursor(14,1); lcd.print("PM"); big.writeint(0,0,ptm->tm_hour - 12,2,false); // 13:00 to 23:59 -> 1:00 PM to 11:59 PM } delay(10000); }