#include "RTClib.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
int16_t x1, y1;
uint16_t textWidth, textHeight;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup () {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void loop () {
display.clearDisplay();
DateTime now = rtc.now();
if(now.hour() >= 10 && now.minute() >= 10){
String tempString = String(now.hour()) + ":" + String(now.minute());
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.getTextBounds(tempString, 0, 0, &x1, &y1, &textWidth, &textHeight);
display.setCursor(64 - (textWidth / 2), 32 - (textHeight / 2));
display.print(tempString);
}
if(now.hour() < 10 && now.minute() >= 10){
String tempString = "0" + String(now.hour()) + ":" + String(now.minute());
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.getTextBounds(tempString, 0, 0, &x1, &y1, &textWidth, &textHeight);
display.setCursor(64 - (textWidth / 2), 32 - (textHeight / 2));
display.print(tempString);
}
if(now.hour() >= 10 && now.minute() < 10){
String tempString = String(now.hour()) + ":" + "0" + String(now.minute());
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.getTextBounds(tempString, 0, 0, &x1, &y1, &textWidth, &textHeight);
display.setCursor(64 - (textWidth / 2), 32 - (textHeight / 2));
display.print(tempString);
}
if(now.hour() < 10 && now.minute() < 10){
String tempString = "0" + String(now.hour()) + ":" + "0" + String(now.minute());
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.getTextBounds(tempString, 0, 0, &x1, &y1, &textWidth, &textHeight);
display.setCursor(64 - (textWidth / 2), 32 - (textHeight / 2));
display.print(tempString);
}
display.display();
}