#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() {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(0);
Wire.endTransmission();
if (Wire.requestFrom(DS1307_ADDRESS, 7) == 7) {
lcd.clear();
int sec=bcdtodec(wire.read());
Serial.print(sec);
Serial.print(" Seconds, ");
lcd.setCursor(0,0);
lcd.print("Seconds : ");
lcd.print(sec);
int minutes=bcdtodec(wire.read());
Serial.print(minutes);
Serial.print(" minutes, ");
lcd.setCursor(0,1);
lcd.print("MINUTES : ");
lcd.print(minutes);
int hours=bcdtodec(wire.read());
Serial.print(hours);
Serial.print(" hours, ");
lcd.setCursor(0,2);
lcd.print("HOURS : ");
lcd.print(hours);
}
else {
Serial.println(F("Failed to get RTC date and time"));
};
delay(1000);
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}