// #include <LiquidCrystal_I2C.h>
// // set the LCD number of columns and rows
// int lcdColumns = 16;
// int lcdRows = 2;
// // set LCD address, number of columns and rows
// // if you don't know your display address, run an I2C scanner sketch
// LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
// void setup(){
// // initialize LCD
// lcd.init();
// // turn on LCD backlight
// lcd.backlight();
// }
// void loop(){
// // set cursor to first column, first row
// lcd.setCursor(0, 0);
// // print message
// lcd.print("Hello, World!");
// delay(1000);
// // clears the display to print new message
// lcd.clear();
// // set cursor to first column, second row
// lcd.setCursor(0,1);
// lcd.print("Hello, World!");
// delay(1000);
// lcd.clear();
// }
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "RTClib.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;
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
void setup ()
{
Serial.begin(9600);
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("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
rtc.adjust(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:
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
}
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop ()
{
DateTime now = rtc.now();
Day = now.day();
Month = now.month();
Year = now.year();
Secs = now.second();
Hours = now.hour();
Minutes = now.minute();
dofweek = daysOfTheWeek[now.dayOfTheWeek()];
myDate = myDate +dofweek+ " "+ Day + "/" + Month + "/" + Year ;
myTime = myTime + Hours +":"+ Minutes +":" + Secs ;
// send to serial monitor
Serial.println(dofweek);
Serial.println(myDate);
Serial.println(myTime);
//Print on lcd
lcd.setCursor(0, 0);
// print message
lcd.print(myDate);
lcd.setCursor(0, 1);
// print message
lcd.print(myTime);
// clears the display to print new message
myDate = "";
myTime = "";
delay(1000);
lcd.clear();
}