#include <Adafruit_NeoPixel.h>
#include <Arduino.h>
#define PIN_H5 2
#define PIN_H1 3
#define PIN_M5 4
#define PIN_M1 5
#define N_H5 4
#define N_H1 4
#define N_M5 11
#define N_M1 4
Adafruit_NeoPixel stripH5(N_H5, PIN_H5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripH1(N_H1, PIN_H1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripM5(N_M5, PIN_M5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripM1(N_M1, PIN_M1, NEO_GRB + NEO_KHZ800);
unsigned long lastUpdate = 0;
const unsigned long interval = 20000; // 20 000 ms = 20 s
// Generiert eine Zufallszeit, gibt sie per Serial aus und setzt die LEDs
void showRandomTime() {
byte hours = random(0, 24);
byte minutes = random(0, 60);
// Serial-Output
Serial.print("Random Time: ");
if (hours < 10) Serial.print('0');
Serial.print(hours);
Serial.print(':');
if (minutes < 10) Serial.print('0');
Serial.println(minutes);
// Blöcke berechnen
byte b5 = hours / 5;
byte b1 = hours % 5;
byte m5 = minutes / 5;
byte m1 = minutes % 5;
// Zeile H5 (4 LEDs, rot)
for (byte i = 0; i < N_H5; i++) {
byte idx = N_H5 - 1 - i;
stripH5.setPixelColor(idx, i < b5 ? stripH5.Color(255,0,0) : 0);
}
stripH5.show();
// Zeile H1 (4 LEDs, rot)
for (byte i = 0; i < N_H1; i++) {
byte idx = N_H1 - 1 - i;
stripH1.setPixelColor(idx, i < b1 ? stripH1.Color(255,0,0) : 0);
}
stripH1.show();
// Zeile M5 (11 LEDs; gelb, 3./6./9. rot)
for (byte i = 0; i < N_M5; i++) {
byte idx = N_M5 - 1 - i;
if (i < m5) {
if (i == 2 || i == 5 || i == 8)
stripM5.setPixelColor(idx, stripM5.Color(255,0,0));
else
stripM5.setPixelColor(idx, stripM5.Color(255,255,0));
} else {
stripM5.setPixelColor(idx, 0);
}
}
stripM5.show();
// Zeile M1 (4 LEDs, gelb)
for (byte i = 0; i < N_M1; i++) {
byte idx = N_M1 - 1 - i;
stripM1.setPixelColor(idx, i < m1 ? stripM1.Color(255,255,0) : 0);
}
stripM1.show();
}
void setup() {
Serial.begin(9600);
while (!Serial); // Warten bis Serial bereit
// Zufallssamen initialisieren
randomSeed(analogRead(A0));
// Strips initialisieren
stripH5.begin(); stripH5.setBrightness(100); stripH5.show();
stripH1.begin(); stripH1.setBrightness(100); stripH1.show();
stripM5.begin(); stripM5.setBrightness(100); stripM5.show();
stripM1.begin(); stripM1.setBrightness(100); stripM1.show();
// Sofort eine erste Zufallszeit anzeigen
showRandomTime();
lastUpdate = millis();
}
void loop() {
if (millis() - lastUpdate >= interval) {
lastUpdate = millis();
showRandomTime();
}
}