Hello everyone,
I am an absolute beginner with little knowledge. I built a linear clock based on the Kassel model.
The circuit is based on an ESP Wroom-32 connected to 14 WS2811, which have the following tasks:
WS2811 #0-2: single-digit seconds (9 LEDs)
WS2811 #3-4: ten-digit seconds (5 LEDs); Output "Blue" of the last WS2811 is not used
WS2811 #5-7: single-digit minutes (9 LEDs)
WS2811 #8-9: ten-digit minutes (5 LEDs); Output "Blue" of the last WS2811 is not used
WS2811 #10-12: single-digit hours (9 LEDs)
WS2811 #13: ten-digit hours (2 LEDs); Output "Blue" of the last WS2811 is not used
I used the FastLED library to control the individual LEDs. To decompose the seconds, minutes and hours into single digits and ten-digits, I used the Modulo (%) operation. The LEDs are activated and deactivated with approx. 40 if > else links. There's probably an easier way, but so far everything works as expected.
If I now disconnect the ESP32 from the power and then reconnect it, some LEDs in almost all areas are not activated immediately (blocks of three LEDs are missing). Only after these are regularly activated by the time they light up again. This can take up to six hours.
What have I already tried?
- Activate/deactivate all LEDs immediately after start, in setup and in loop
- Only one FastLED.show command per block
- Delay when querying the NTP time
I really appreciate your help and know how much time something like this takes.
So thank you very much in advance.
Here is the Arduino sketch:
/*
Project: Linearuhr von NTC Zeit Server mit ESP32
Author: Michael Todtenbier
Date: Created 02.07.2024
Version: V1.0
IDE: Arduino IDE 1.8.19
Required libraries (sketch -> include library -> manage libraries)
-
*/
#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
//#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#define DATA_PIN 27 // Pin für LED-Streifen
#define NUM_LEDS 14 // Anzahl der WS2811-Chips
// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 7200, 60000);
// Wi-Fi Settings
const char *wifi_ssid = "YourSSID";
const char *wifi_password = "YourPassword";
const char* NTP_SERVER = "de.pool.ntp.org";
const char* TZ_INFO = "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00";
/*
time_t now;
tm tm;
*/
void setup () {
Serial.begin(115200);
// Verbindung zu WiFi herstellen
delay(10);
WiFi.begin(wifi_ssid, wifi_password);
int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
if (++counter > 100) ESP.restart();
Serial.print(".");
}
Serial.println("WiFi connected");
//FastLED aktivieren
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
// NTP Client starten
timeClient.begin();
}
void loop () {
timeClient.update();
int hours = timeClient.getHours();
int minutes = timeClient.getMinutes();
int seconds = timeClient.getSeconds();
Serial.printf(" \tUhrzeit: %02d:%02d:%02d \n", hours, minutes, seconds);
//Zehnerstunden
if (((hours / 10) % 10) > 1) {
leds[13] = CRGB::Yellow;
FastLED.show();
}
else if (((hours / 10) % 10) > 0) {
leds[13] = CRGB::Red;
FastLED.show();
}
else {
leds[13] = CRGB::Black;
FastLED.show();
}
//Einerstunden
if ((hours % 10) > 8) {
leds[12] = CRGB::White;
FastLED.show();
}
else if ((hours % 10) > 7) {
leds[12] = CRGB::Yellow;
FastLED.show();
}
else if ((hours % 10) > 6) {
leds[12] = CRGB::Red;
FastLED.show();
}
else if ((hours % 10) > 5) {
leds[11] = CRGB::White;
FastLED.show();
}
else if ((hours % 10) > 4) {
leds[11] = CRGB::Yellow;
FastLED.show();
}
else if ((hours % 10) > 3) {
leds[11] = CRGB::Red;
FastLED.show();
}
else if ((hours % 10) > 2) {
leds[10] = CRGB::White;
FastLED.show();
}
else if ((hours % 10) > 1) {
leds[10] = CRGB::Yellow;
FastLED.show();
}
else if ((hours % 10) > 0) {
leds[10] = CRGB::Red;
FastLED.show();
}
else {
leds[12] = CRGB::Black;
FastLED.show();
leds[11] = CRGB::Black;
FastLED.show();
leds[10] = CRGB::Black;
FastLED.show();
}
//Zehnerminuten
if (((minutes / 10) % 10) > 4) {
leds[9] = CRGB::Yellow;
FastLED.show();
}
else if (((minutes / 10) % 10) > 3) {
leds[9] = CRGB::Red;
FastLED.show();
}
else if (((minutes / 10) % 10) > 2) {
leds[8] = CRGB::White;
FastLED.show();
}
else if (((minutes / 10) % 10) > 1) {
leds[8] = CRGB::Yellow;
FastLED.show();
}
else if (((minutes / 10) % 10) > 0) {
leds[8] = CRGB::Red;
FastLED.show();
}
else {
leds[9] = CRGB::Black;
FastLED.show();
leds[8] = CRGB::Black;
FastLED.show();
}
//Einerminuten
if ((minutes % 10) > 8) {
leds[7] = CRGB::White;
FastLED.show();
}
else if ((minutes % 10) > 7) {
leds[7] = CRGB::Yellow;
FastLED.show();
}
else if ((minutes % 10) > 6) {
leds[7] = CRGB::Red;
FastLED.show();
}
else if ((minutes % 10) > 5) {
leds[6] = CRGB::White;
FastLED.show();
}
else if ((minutes % 10) > 4) {
leds[6] = CRGB::Yellow;
FastLED.show();
}
else if ((minutes % 10) > 3) {
leds[6] = CRGB::Red;
FastLED.show();
}
else if ((minutes % 10) > 2) {
leds[5] = CRGB::White;
FastLED.show();
}
else if ((minutes % 10) > 1) {
leds[5] = CRGB::Yellow;
FastLED.show();
}
else if ((minutes % 10) > 0) {
leds[5] = CRGB::Red;
FastLED.show();
}
else {
leds[7] = CRGB::Black;
FastLED.show();
leds[6] = CRGB::Black;
FastLED.show();
leds[5] = CRGB::Black;
FastLED.show();
}
//Zehnersekunden
if (((seconds / 10) % 10) > 4) {
leds[4] = CRGB::Yellow;
FastLED.show();
}
else if (((seconds / 10) % 10) > 3) {
leds[4] = CRGB::Red;
FastLED.show();
}
else if (((seconds / 10) % 10) > 2) {
leds[3] = CRGB::White;
FastLED.show();
}
else if (((seconds / 10) % 10) > 1) {
leds[3] = CRGB::Yellow;
FastLED.show();
}
else if (((seconds / 10) % 10) > 0) {
leds[3] = CRGB::Red;
FastLED.show();
}
else {
leds[3] = CRGB::Black;
FastLED.show();
leds[4] = CRGB::Black;
FastLED.show();
}
//Einersekunden
if ((seconds % 10) > 8) {
leds[2] = CRGB::White;
FastLED.show();
}
else if ((seconds % 10) > 7) {
leds[2] = CRGB::Yellow;
FastLED.show();
}
else if ((seconds % 10) > 6) {
leds[2] = CRGB::Red;
FastLED.show();
}
else if ((seconds % 10) > 5) {
leds[1] = CRGB::White;
FastLED.show();
}
else if ((seconds % 10) > 4) {
leds[1] = CRGB::Yellow;
FastLED.show();
}
else if ((seconds % 10) > 3) {
leds[1] = CRGB::Red;
FastLED.show();
}
else if ((seconds % 10) > 2) {
leds[0] = CRGB::White;
FastLED.show();
}
else if ((seconds % 10) > 1) {
leds[0] = CRGB::Yellow;
FastLED.show();
}
else if ((seconds % 10) > 0) {
leds[0] = CRGB::Red;
FastLED.show();
}
else {
leds[2] = CRGB::Black;
FastLED.show();
leds[1] = CRGB::Black;
FastLED.show();
leds[0] = CRGB::Black;
FastLED.show();
}
}



