0% found this document useful (0 votes)
8 views1 page

New 4

Uploaded by

june cadayona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

New 4

Uploaded by

june cadayona
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <LiquidCrystal_I2C.

h>
#include <ThreeWire.h>
#include <RtcDS1302.h>

// LCD address (0x3F or 0x27)


LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD Object
ThreeWire myWire(11, 10, 12); // DAT, CLK, RST
RtcDS1302<ThreeWire> Rtc(myWire); // RTC Object

void setup() {
lcd.begin();
lcd.backlight();
lcd.clear();

Rtc.Begin();

RtcDateTime currentTime = RtcDateTime(__DATE__, __TIME__);


Rtc.SetDateTime(currentTime);
}

void loop() {
RtcDateTime now = Rtc.GetDateTime();

// Clear the LCD and print the date and time


lcd.clear();

// Print the date in DD/MM/YYYY format


lcd.setCursor(0, 0);
lcd.print("Date: ");
if (now.Day() < 10) lcd.print('0'); // Add leading zero if day < 10
lcd.print(now.Day());
lcd.print("/");
if (now.Month() < 10) lcd.print('0'); // Add leading zero if month < 10
lcd.print(now.Month());
lcd.print("/");
lcd.print(now.Year());

// Print the time in HH:MM:SS format


lcd.setCursor(0, 1);
lcd.print("Time: ");
if (now.Hour() < 10) lcd.print('0'); // Add leading zero if hour < 10
lcd.print(now.Hour());
lcd.print(":");
if (now.Minute() < 10) lcd.print('0'); // Add leading zero if minute < 10
lcd.print(now.Minute());
lcd.print(":");
if (now.Second() < 10) lcd.print('0'); // Add leading zero if second < 10
lcd.print(now.Second());

delay(500);
}

You might also like