0% found this document useful (0 votes)
2 views3 pages

Clock

This document contains a code for displaying the current date and time on a 16x2 LCD using an RTC module. It initializes the RTC, sets up the LCD, and continuously updates the display with the current date and time. The code also includes functionality to handle RTC power loss and set the time accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Clock

This document contains a code for displaying the current date and time on a 16x2 LCD using an RTC module. It initializes the RTC, sets up the LCD, and continuously updates the display with the current date and time. The code also includes functionality to handle RTC power loss and set the time accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Clock ⌚

//Tech Trends Shameer


//Display Date and Time in LCD Display

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
RTC_DS3231 rtc;

char daysOfTheWeek[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

int Day;
int Month;
int Year;
int Secs;
int Minutes;
int Hours;

String dofweek; // day of week

String myDate;
String myTime;

// for the 16x2 LCD

#define rs 9
#define en 8
#define d4 7
#define d5 6
#define d6 5
#define d7 4
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup ()
{
[Link](9600);
[Link]();
delay(3000); // wait for console opening

if (! [Link]()) {
[Link]("Couldn't find RTC");
while (1);
}
if ([Link]()) {
[Link]("RTC lost power, lets set the time!");

// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
[Link](DateTime(F(__DATE__), F(__TIME__)));

// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// [Link](DateTime(2017, 1, 27, 12, 56, 0));
}

[Link]();
[Link]();
[Link](3,0);
[Link]("Tech Trends");
[Link](5,1);
[Link]("Shameer");
delay(3000);
[Link]();
}

void loop ()
{
DateTime now = [Link]();
[Link]();
Day = [Link]();
Month = [Link]();
Year = [Link]();
Secs = [Link]();
Hours = [Link]();
Minutes = [Link]();
dofweek = daysOfTheWeek[[Link]()];

myDate = myDate +dofweek+ " "+ Day + "/" + Month + "/" + Year ;
myTime = myTime + Hours +":"+ Minutes +":" + Secs ;
// send to serial monitor
[Link](dofweek);
[Link](myDate);
[Link](myTime);
//Print on lcd
[Link](0,0);
[Link](myDate);
[Link](0,1);
[Link]("Time:");
[Link](6,1);
[Link](myTime);
myDate = "";
myTime = "";
delay(1000);
}

You might also like