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);
}