#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DS1307_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27, 20, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int count = 0, last_count = -1;
void setup() {
Serial.begin(115200);
Serial.println("Hello");
Wire.begin();
lcd.init();
lcd.backlight();
lcd.print("Serial counter Example");
delay(1000);
}
void loop() {
lcd.clear();
lcd.setCursor(3,0);
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(0);
Wire.endTransmission();
if (Wire.requestFrom(DS1307_ADDRESS, 7) == 7) {
int sec= bcdToDec(Wire.read());
lcd.print("Sec:"+String(sec));
int min=bcdToDec(Wire.read());
lcd.setCursor(3,1);
lcd.print("Min:"+String(min));
int hr=bcdToDec(Wire.read());
lcd.setCursor(3,2);
lcd.print("Hr:"+String(hr));
}
else {
Serial.println(F("Failed to get RTC date and time"));
};
delay(1000);
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}