#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DS1307_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27, 20, 2);
void setup() {
Serial.begin(115200);
Serial.println("Hello");
Wire.begin();
lcd.init();
lcd.backlight();
lcd.print("Serial counter Example");
delay(1000);
}
void loop() {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(0);
Wire.endTransmission();
if (Wire.requestFrom(DS1307_ADDRESS, 7) == 7) {
Serial.print(bcdToDec(Wire.read()));
Serial.print(" seconds, ");
Serial.print(bcdToDec(Wire.read()));
Serial.print(" minutes, ");
Serial.print(bcdToDec(Wire.read()));
Serial.print(" hours, ");
Serial.print(bcdToDec(Wire.read()));
Serial.print(" day of week, ");
Serial.print(bcdToDec(Wire.read()));
Serial.print(" day, ");
Serial.print(bcdToDec(Wire.read()));
Serial.print(" month, ");
Serial.print(bcdToDec(Wire.read())+2000);
Serial.println(" year");
}
else {
Serial.println(F("Failed to get RTC date and time"));
};
delay(1000);
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}