//LCD
#include <LiquidCrystal.h>
//*************** LCD hardware
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//RTC
#include <RTClib.h>
RTC_DS3231 rtc;
char t[32];
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
//LCD
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//RTC
// put your setup code here, to run once:
Serial.begin(9600); // to see in serial monitor dont use this Serial.begin if pin 0,1 is used for high or low, in this project it is used
// Serial.begin(115200);
Wire.begin();
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); // loads from system timeing
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
// sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
//sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
sprintf(t, "%02d:%02d:%02d:%s", now.day(),now.month() , now.year(),daysOfTheWeek[now.dayOfTheWeek()]);
Serial.println(t);
//Serial.println("Hello OK!");
delay(1000);
// DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
// delay(3000);
// LCD show
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(t);
lcd.setCursor(0, 1);
lcd.print("9902037956");
delay(2000);
lcd.clear();
}