#include <FastLED.h>
#include <vector>
#include <WiFi.h>
// 000 001 002 003 004 005 006 007 008 009 010 011 012 013
// E S - I S T - N U L L E I N
// 027 026 025 024 023 022 021 020 019 018 017 016 015 014
// Z W E I - D R E I - V I E R
// 028 029 030 031 032 033 034 035 036 037 038 039 040 041
// - - F Ü N F - S E C H S - -
// 055 054 053 052 051 050 049 048 047 046 045 044 043 042
// S I E B E N A C H T N E U N
// 056 057 058 059 060 061 062 063 064 065 066 067 068 069
// Z E H N - E L F - Z W Ö L F
// 083 082 081 080 079 078 077 076 075 074 073 072 071 070
// U N D - - Z W A N Z I G - -
// 084 085 086 087 088 089 090 091 092 093 094 095 096 097
// U H R - E I N S - Z W E I -
// 111 110 109 108 107 106 105 104 103 102 101 100 099 098
// D R E I - V I E R - F Ü N F
// 112 113 114 115 116 117 118 119 120 121 122 123 124 125
// - S E C H S - S I E B E N -
// 139 138 137 136 135 134 133 132 131 130 129 128 127 126
// A C H T - N E U N - Z E H N
// 140 141 142 143 144 145 146 147 148 149 150 151 152 153
// U N D - E L F - Z W Ö L F -
// 167 166 165 164 163 162 161 160 159 158 157 156 155 154
// Z W A N Z I G D R E I ß I G
// 168 169 170 171 172 173 174 175 176 177 178 179 180 181
// V I E R Z I G F Ü N F Z I G
struct Silbe {
uint8_t start;
uint8_t length;
};
using Zahl = std::vector<const Silbe*>;
namespace Permanent {
const Silbe es {0, 2};
const Silbe ist {3, 3};
const Silbe uhr {84, 3};
}
namespace Stunden {
const Silbe _null {7, 4};
const Silbe ein{11, 3};
const Silbe zwei{24, 4};
const Silbe drei{20, 4};
const Silbe vier{14, 4};
const Silbe fuenf{30, 5};
const Silbe sech{35, 4};
const Silbe sechs{35, 5};
const Silbe sieb{52, 4};
const Silbe sieben{50, 6};
const Silbe acht{46, 4};
const Silbe neun{42, 4};
const Silbe zehn{56, 4};
const Silbe elf{61, 3};
const Silbe zwoelf{65, 5};
const Silbe und{81, 3};
const Silbe zwanzig{72, 7};
std::vector<Zahl> zahlen {
{{&_null}},
{{&ein}},
{{&zwei}},
{{&drei}},
{{&vier}},
{{&fuenf}},
{{&sechs}},
{{&sieben}},
{{&acht}},
{{&neun}},
{{&zehn}},
{{&elf}},
{{&zwoelf}},
{{&drei}, {&zehn}},
{{&vier}, {&zehn}},
{{&fuenf}, {&zehn}},
{{&sech}, {&zehn}},
{{&sieb}, {&zehn}},
{{&acht}, {&zehn}},
{{&neun}, {&zehn}},
{{&zwanzig}},
{{&ein}, {&und}, {&zwanzig}},
{{&zwei}, {&und}, {&zwanzig}},
{{&drei}, {&und}, {&zwanzig}}
};
}
namespace Minuten {
const Silbe _null {0, 0};
const Silbe ein{88, 3};
const Silbe eins{88, 4};
const Silbe zwei{93, 4};
const Silbe drei{108, 4};
const Silbe vier{103, 4};
const Silbe fuenf{98, 4};
const Silbe sech{113, 4};
const Silbe sechs{113, 5};
const Silbe sieb{119, 4};
const Silbe sieben{119, 6};
const Silbe acht{136, 4};
const Silbe neun{131, 4};
const Silbe zehn{126, 4};
const Silbe und{140, 3};
const Silbe elf{144, 3};
const Silbe zwoelf{148, 5};
const Silbe zwanzig{161, 7};
const Silbe dreiszig{154, 7};
const Silbe vierzig{168, 7};
const Silbe fuenfzig{175, 7};
std::vector<Zahl> zahlen {
{{&_null}},
{{&ein}},
{{&zwei}},
{{&drei}},
{{&vier}},
{{&fuenf}},
{{&sechs}},
{{&sieben}},
{{&acht}},
{{&neun}},
{{&zehn}},
{{&elf}},
{{&zwoelf}},
{{&drei}, {&zehn}},
{{&vier}, {&zehn}},
{{&fuenf}, {&zehn}},
{{&sech}, {&zehn}},
{{&sieb}, {&zehn}},
{{&acht}, {&zehn}},
{{&neun}, {&zehn}},
{{&zwanzig}},
{{&ein}, {&und}, {&zwanzig}},
{{&zwei}, {&und}, {&zwanzig}},
{{&drei}, {&und}, {&zwanzig}},
{{&vier}, {&und}, {&zwanzig}},
{{&fuenf}, {&und}, {&zwanzig}},
{{&sechs}, {&und}, {&zwanzig}},
{{&sieben}, {&und}, {&zwanzig}},
{{&acht}, {&und}, {&zwanzig}},
{{&neun}, {&und}, {&zwanzig}},
{{&dreiszig}},
{{&ein}, {&und}, {&dreiszig}},
{{&zwei}, {&und}, {&dreiszig}},
{{&drei}, {&und}, {&dreiszig}},
{{&vier}, {&und}, {&dreiszig}},
{{&fuenf}, {&und}, {&dreiszig}},
{{&sechs}, {&und}, {&dreiszig}},
{{&sieben}, {&und}, {&dreiszig}},
{{&acht}, {&und}, {&dreiszig}},
{{&neun}, {&und}, {&dreiszig}},
{{&vierzig}},
{{&ein}, {&und}, {&vierzig}},
{{&zwei}, {&und}, {&vierzig}},
{{&drei}, {&und}, {&vierzig}},
{{&vier}, {&und}, {&vierzig}},
{{&fuenf}, {&und}, {&vierzig}},
{{&sechs}, {&und}, {&vierzig}},
{{&sieben}, {&und}, {&vierzig}},
{{&acht}, {&und}, {&vierzig}},
{{&neun}, {&und}, {&vierzig}},
{{&fuenfzig}},
{{&ein}, {&und}, {&fuenfzig}},
{{&zwei}, {&und}, {&fuenfzig}},
{{&drei}, {&und}, {&fuenfzig}},
{{&vier}, {&und}, {&fuenfzig}},
{{&fuenf}, {&und}, {&fuenfzig}},
{{&sechs}, {&und}, {&fuenfzig}},
{{&sieben}, {&und}, {&fuenfzig}},
{{&acht}, {&und}, {&fuenfzig}},
{{&neun}, {&und}, {&fuenfzig}}
};
}
const size_t NUM_LEDS = 182;
CRGB leds[NUM_LEDS];
std::vector<const Silbe*> timeToLEDs(uint8_t stunde, uint8_t minute) {
std::vector<const Silbe*> result;
result.push_back(&Permanent::es);
result.push_back(&Permanent::ist);
for (auto silbe : Stunden::zahlen[stunde]) result.push_back(silbe);
result.push_back(&Permanent::uhr);
for (auto silbe : Minuten::zahlen[minute]) result.push_back(silbe);
return result;
}
void fillLEDs(std::vector<const Silbe*> silben) {
for (auto& led : leds) led = CRGB::Black;
for (auto silbe : silben) {
for (size_t i = 0; i < silbe->length; i++) leds[silbe->start + i] = CRGB::Red;
FastLED.show();
}
}
void setupLEDs() {
FastLED.addLeds<WS2812B, 13, GRB>(leds, NUM_LEDS);
}
void setupWiFi() {
WiFi.onEvent([](arduino_event_id_t event, arduino_event_info_t info) {
Serial.printf("WiFi connected: %s\r\n", WiFi.localIP().toString().c_str());
}, ARDUINO_EVENT_WIFI_STA_GOT_IP);
WiFi.begin("Wokwi-GUEST", "", 6);
}
void setupNTP() {
configTime(0, 0, "europe.pool.ntp.org"); // 0, 0 because we will use TZ in the next line
setenv("TZ", "CET-1CEST,3.5.0/2:00,10.5.0/3:00", 1);
}
void printTime() {
tm timeinfo;
static uint8_t lastSecond;
static int8_t lastMinute = -1;
while (!getLocalTime(&timeinfo, 100)) return;
if (timeinfo.tm_sec == lastSecond) return;
lastSecond = timeinfo.tm_sec;
Serial.printf("%02d:%02d:%02d\r\n", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
if (lastMinute >-1 && timeinfo.tm_min == lastMinute) return;
lastMinute = timeinfo.tm_min;
fillLEDs(timeToLEDs(timeinfo.tm_hour, timeinfo.tm_min));
}
void setup() {
Serial.begin(115200);
setupLEDs();
setupWiFi();
setupNTP();
}
void loop() {
printTime();
delay(10); // wokwi delay
}
E_____S____M_____I____S_____T___M____N____U____L_____L_____E____I____N
Z____W____E_____I_____M____D____R____E____I_____M____V____I____E_____R
M____N____F____Ü_____N____F____N____S____E____C_____H____S____M___M
.S_.___I_____E____B____.E_____N.___A____C____H____T____.N____E____U____N
.Z__.__E__.__H____N_.__M____E____L_____F____M____Z__._W__._Ö___._L____F
.U____N____D___.M____M___.Z____W___.A____N____Z_____I____G____M___.M
.U____H____R____M____E__.__I__.__N____S_..__M____Z____W_.__E_____I_..__M
.D____R__.__E___._I__.__M_.__V__.__I_____E____R____M____F____Ü__.__N__._F
.M_.__S__.__E____C__.__H____S____M____S___._I_____E____B__.__E____N__._M
.A____C__.__H____T____M__._N____E____U__.__N__._M____Z____E__.__H____N
.U____N____D__._M____E__.__L__.__F____M____Z____W_.__Ö____L__.__F____M
.Z____W____A____N____Z__.__I__.__G____D____R____E_____I__.__ß_____I__.__G
.V__.__I__.__E__.__R____Z__.__I__.__G_____F____Ü____N____F__.__Z_____I__.__G