#include <WiFi.h>
#include "time.h"
#include <FastLED.h>
#include <Wire.h>
// WiFi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Zeitzone für automatische Sommer-/Winterzeitregelung
const char* timeZone = "CET-1CEST,M3.5.0/2,M10.5.0/3";
// LED settings
#define NUM_LEDS 60
#define DATA_PIN 2
#define hourColor CRGB::Blue;
#define minuteColor CRGB::Green;
#define secondColor CRGB::Red;
#define HMoverlap CRGB::Cyan;
#define MSoverlap CRGB::Yellow;
#define SHoverlap CRGB::Purple;
unsigned long actTime = 0;
unsigned long remTime = 0;
const unsigned long period = 500;
bool blinkState = false;
bool toggleSeconds = true;
int BRIGHTNESS = 180;
const int brightnessButton = 4;
boolean buttonPrev = false;
CRGB leds[NUM_LEDS];
int periodic[NUM_LEDS] = {0, 58, 59, 57, 56, 55, 54, 53, 52, 51, 50, 42, 43, 44, 45, 46, 47, 48, 49, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 5, 4, 3, 2, 1};
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize NTP with time zone for automatic DST
configTzTime(timeZone, "pool.ntp.org", "time.nist.gov");
pinMode(brightnessButton, INPUT);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
adjustBrightness();
FastLED.clear();
showTime();
delay(1000);
}
void showTime() {
time_t now;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
now = mktime(&timeinfo);
int currentHour = timeinfo.tm_hour;
int currentMinute = timeinfo.tm_min;
int currentSecond = timeinfo.tm_sec;
if ((currentSecond == currentMinute) && toggleSeconds) {
leds[periodic[currentSecond]] = MSoverlap;
leds[periodic[currentHour]] = hourColor;
} else if ((currentSecond == currentHour) && toggleSeconds) {
leds[periodic[currentSecond]] = SHoverlap;
leds[periodic[currentMinute]] = minuteColor;
} else if (currentMinute == currentHour) {
if (toggleSeconds) leds[periodic[currentSecond]] = secondColor;
leds[periodic[currentMinute]] = HMoverlap;
} else {
if (toggleSeconds) leds[periodic[currentSecond]] = secondColor;
leds[periodic[currentMinute]] = minuteColor;
leds[periodic[currentHour]] = hourColor;
}
FastLED.show();
// Clear the LEDs after showing time
leds[periodic[currentSecond]] = CRGB::Black;
leds[periodic[currentMinute]] = CRGB::Black;
leds[periodic[currentHour]] = CRGB::Black;
}
void adjustBrightness() {
if (digitalRead(brightnessButton) && buttonPrev) {
BRIGHTNESS = (BRIGHTNESS < 255) ? BRIGHTNESS + 51 : 51;
FastLED.setBrightness(BRIGHTNESS);
Serial.print("Brightness set to: ");
Serial.println(BRIGHTNESS);
}
buttonPrev = !digitalRead(brightnessButton);
}