#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_SSD1306.h>
#define H_PIN 5
#define M_PIN 4
#define BUTTON_PIN 6
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 anzeige(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS1307 rtc;
void setup() {
Serial.begin(115200);
if (!anzeige.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("Fehler: OLED nicht gefunden!");
while (1);
}
if (!rtc.begin()) {
Serial.println("Fehler: RTC nicht gefunden!");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC wurde neu gestartet, setze Zeit...");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(H_PIN, INPUT_PULLUP);
pinMode(M_PIN, INPUT_PULLUP);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void currenttime() {
DateTime now = rtc.now();
byte hour = now.hour();
byte minute = now.minute();
anzeige.clearDisplay();
anzeige.setTextSize(2);
anzeige.setTextColor(SSD1306_WHITE);
anzeige.setCursor(10, 20);
if (hour < 10) anzeige.print("0");
anzeige.print(hour);
anzeige.print(":");
if (minute < 10) anzeige.print("0");
anzeige.println(minute);
anzeige.display();
}
void loop() {
currenttime();
delay(1000); // Aktualisiere jede Sekunde
}