//sketch created by Akshay Joseph
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 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
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin(16,2);
lcd.backlight();
lcd.clear();
lcd.setCursor(4,0);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void loop()
{
DateTime now = rtc.now();
lcd.clear();
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
//Print on lcd
lcd.setCursor(0,0);
// lcd.print(myDate);
// lcd.setCursor(0,1);
lcd.print(myTime);
lcd.setCursor(12,0);
lcd.print(dofweek);
myDate = "";
myTime = "";
delay(1000);
}