#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
RTC_DS1307 RTC;
Adafruit_SSD1306 OLED = Adafruit_SSD1306(128, 64, & Wire);
void setup() {
Wire.begin();
RTC.begin();
OLED.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
DateTime now = RTC.now();
OLED.clearDisplay();
OLED.setTextColor(WHITE);
OLED.setTextSize(1);
OLED.setCursor(0,0);
OLED.print("TIME");
OLED.setTextSize(2);
OLED.setCursor(0,10);
OLED.print(now.hour() < 10 ? "0" : "");
OLED.print(now.hour(), DEC);
OLED.print(":");
OLED.print(now.minute() < 10 ? "0" : "");
OLED.print(now.minute(), DEC);
OLED.print(":");
OLED.print(now.second() < 10 ? "0" : "");
OLED.println(now.second(), DEC);
OLED.setTextSize(2);
OLED.setCursor(90, 10);
if (now.hour() < 12) {
OLED.print(" AM");
} else if (now.hour() >= 12) {
OLED.print(" PM");
}
OLED.setTextSize(1);
OLED.setCursor(0,35);
OLED.print("DATE");
OLED.setTextSize(2);
OLED.setCursor(0,45);
OLED.print(now.month() < 10 ? "0" : "");
OLED.print(now.month(), DEC);
OLED.print(".");
OLED.print(now.day() < 10 ? "0" : "");
OLED.print(now.day(), DEC);
OLED.print(".");
OLED.print(now.year() < 10 ? "0" : "");
OLED.println(now.year(), DEC);
delay(100);
OLED.display();
OLED.dim(true);
delay(500);
OLED.dim(false);
delay(500);
}