#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
RTC_DS3231 rtc;
char t[32];
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
}
void loop() {
// put your main code here, to run repeatedly:
// Printing the results on the serial monitor
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
DateTime now = rtc.now();
sprintf(t, "%02d:%02d:%02d", now.hour()-12, now.minute(), now.second());
Serial.print(F("Date/Time: "));
Serial.println(t);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(15, 10);
display.print(t);
sprintf(t, "%02d-%02d-%02d", now.day(), now.month(), now.year());
Serial.print(F("Date/Time: "));
Serial.println(t);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(5, 40);
display.print(t);
display.display();
}