#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TimeLib.h>
const int lcdAddr = 0x27; // I2C address of your LCD
LiquidCrystal_I2C lcd(lcdAddr, 16, 2); // Change the dimensions if your LCD is different
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // Initialize the LCD with the specified dimensions
setTime(8, 50, 0, 28, 12, 2023); // set time to 8:50:00, Dec 28, 2023
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(hour());
printDigits(minute());
printDigits(second());
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(day());
lcd.print(" ");
lcd.print(month());
lcd.print(" ");
lcd.print(year());
}
void printDigits(int digits)
{
lcd.print(":");
if (digits < 10)
lcd.print('0');
lcd.print(digits);
}