#include <WiFi.h>
#include <Wire.h>
#include <FastLED.h>
#define PIN 2
#define NUMPIXELS 114
CRGB leds[NUMPIXELS];
uint8_t h1, h2, m1, m2, sec, sec_old;
long szamok[] = {
0b1111111111111111000011111111, // 0
0b1111000000001111000000000000, // 1
0b1111111111110000111100001111, // 2
0b1111000011111111111100001111, // 3
0b1111000000001111111111110000, // 4
0b0000000011111111111111111111, // 5
0b0000111111111111111111111111, // 6
0b1111000000001111000000001111, // 7
0b1111111111111111111111111111, // 8
0b1111111111111111111100001111 // 9
};
bool blink = 0;
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 3600
#define UTC_OFFSET_DST 0
void chkLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Connection Err");
return;
}
uint8_t nowHour = timeinfo.tm_hour;
uint8_t nowMinute = timeinfo.tm_min;
h1 = nowHour / 10;
h2 = nowHour - (nowHour / 10 * 10);
m1 = nowMinute / 10;
m2 = nowMinute - (nowMinute / 10 * 10);
sec = timeinfo.tm_sec;
}
void setup() {
Serial.begin(115200);
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUMPIXELS);
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
for (int i = 0; i < 114; i++) {
leds[i] = CRGB(84, 18, 207);
FastLED.show();
delay(5);
}
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Online");
Serial.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
chkLocalTime();
if (sec != sec_old) {
sec_old = sec;
colorClockPixels(sec);
Serial.println(sec);
blink = !blink;
if (blink) {
leds[56] = rainbowColor(sec);
leds[57] = rainbowColor(sec);
FastLED.show();
}
else {
leds[56] = CRGB(0, 0, 0);
leds[57] = CRGB(0, 0, 0);
FastLED.show();
}
}
delay(500);
}
void colorClockPixels(uint8_t seconds) {
for (int i = 0; i < 28; i++) {
if ((szamok[h1] & (1 << i)) != 0) {
leds[i] = rainbowColor(seconds);
} else {
leds[i] = CRGB(0, 0, 0);
}
}
for (int i = 0; i < 28; i++) {
if ((szamok[h2] & (1 << i)) != 0) {
leds[i + 28] = rainbowColor(seconds);
} else {
leds[i + 28] = CRGB(0, 0, 0);
}
}
for (int i = 0; i < 28; i++) {
if ((szamok[m1] & (1 << i)) != 0) {
leds[i + 58] = rainbowColor(seconds);
} else {
leds[i + 58] = CRGB(0, 0, 0);
}
}
for (int i = 0; i < 28; i++) {
if ((szamok[m2] & (1 << i)) != 0) {
leds[i + 86] = rainbowColor(seconds);
} else {
leds[i + 86] = CRGB(0, 0, 0);
}
}
FastLED.show();
}
CRGB rainbowColor(uint8_t seconds) {
uint8_t hue = map(seconds, 0, 59, 0, 255);
return CHSV(hue, 255, 255);
}