#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <ESP32Time.h>
#define Sprintln(a) (Serial.println(a))
#define Sprint(a) (Serial.print(a))
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16,2);
//ESP32Time rtc;
ESP32Time rtc(25200); // offset in seconds Thailand GMT+7 : 7 * 60 * 60 : 25200
// Init a Time-data structure
void setup()
{
Serial.begin(115200);
/*******************************************/
LCD.init(); // initial LCD on lib
LCD.backlight(); // Blink LCD backlight on
LCD.setCursor(0,0); // Clear LCD display
LCD.print("Hello world");
LCD.setCursor(0,1);
LCD.print("Mechatronics Eng");
delay (2000);
/*******************************************/
rtc.setTime(30, 10, 7, 19, 3, 2022); // 17th Jan 2022 14:10:30
/*******************************************/
}
void loop()
{
// Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S")); // (String) returns time with specified format
// formating options http://www.cplusplus.com/reference/ctime/strftime/
struct tm timeinfo = rtc.getTimeStruct();
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); // (tm struct) Sunday, January 17 2021 07:24:38
LCD.setCursor(0,0);
LCD.print("Date: ");
LCD.print(&timeinfo, "%A");
LCD.setCursor(0,1);
LCD.print("Time: ");
LCD.print(&timeinfo, " %H:%M:%S ");
delay(1000);
}