#include <Wire.h>
#include <RTClib.h>
#include <U8g2lib.h>
RTC_DS1307 rtc;
// U8g2 Constructor for your display, please update the parameters accordingly
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is not running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
u8g2.begin();
}
void loop() {
DateTime now = rtc.now();
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 10);
u8g2.print(now.day(), DEC);
u8g2.print('/');
u8g2.print(now.month(), DEC);
u8g2.print('/');
u8g2.print(now.year(), DEC);
u8g2.setCursor(0,30);
u8g2.print(now.hour(), DEC);
u8g2.print(':');
u8g2.print(now.minute(), DEC);
u8g2.print(':');
u8g2.print(now.second(), DEC);
} while (u8g2.nextPage());
delay(1000); // doesn't have to be 1000
}