#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Include the I2C LCD library
#include <DS3231.h> // Include the DS3231 library
// DS3231 I2C address
#define DS3231_ADDRESS 0x68
// Initialize the LCD (change the address if needed)
LiquidCrystal_I2C lcd(0x27, 20, 4); // Adjust the address and dimensions
DS3231 rtc;
void setup() {
Wire.begin();
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the backlight
}
void loop() {
DateTime dataehora = rtc.getDate(); // Read time from DS3231
// Print time to LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(dataehora.hour());
lcd.print(":");
lcd.print(dataehora.minute());
lcd.print(":");
lcd.print(dataehora.second());
// Print date to LCD
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(dataehora.year());
lcd.print("-");
lcd.print(dataehora.month());
lcd.print("-");
lcd.print(dataehora.day());
delay(1000); // Update every second
}