#include <RTClib.h>
#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according
RTC_DS1307 rtc;
char daysOfWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
lcd.begin();
lcd.backlight();
// SETUP RTC MODULE
if (! rtc.begin()) {
Serial.println("RTC module is NOT found");
Serial.flush();
while (1);
}
// automatically sets the RTC to the date & time on PC this sketch was compiled
//asal nya
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
DateTime now = rtc.now();
rtc.adjust(DateTime(2025,now.month(),now.day(),now.hour(),now.minute(),now.second()));
// manually sets the RTC with an explicit date & time, for example to set
// January 21, 2021 at 3am you would call:
// rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0));
}
void loop() {
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
DateTime now = rtc.now();
//DateTime now = new DateTime();
Serial.print("ESP32 RTC Date Time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
//delay(1000); // delay 1 seconds
//String time_ = now.year() + '/' + now.month() + '/' + now.day() ;
// String time_ = String( (now.year(), DEC) + '/' + (now.month(), DEC) + '/' + (now.day(), DEC) );
//String time_ = String( now.year() ) + "/" + String( now.month() ) + "/" + String( now.day() ) + " " + String( now.hour() ) + ":" + String( now.minute() ) + ":" + String( now.second() );
String time_ = String( now.year() ) + "/" + String( now.month() ) + "/" + String( now.day() ) ;
lcd.setCursor(0, 0); // Or setting the cursor in the desired position.
lcd.println(time_);
String time__ = String( now.hour() ) + ":" + String( now.minute() ) + ":" + String( now.second() );
lcd.setCursor(0, 1); // Or setting the cursor in the desired position.
lcd.println(time__);
delay(1000);
//lcd.clear();
}