#include <WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <time.h>
#define LED_PIN 2
#define LED_COUNT 58
#define BRIGHTNESS 255
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 7 * 3600; // GMT+7 (Indonesia)
const int daylightOffset_sec = 0;
// 7-segment font table
// A B C D E F G
const byte digitMap[10][7] = {
{1,1,1,1,1,1,0}, // 0
{0,1,1,0,0,0,0}, // 1
{1,1,0,1,1,0,1}, // 2
{1,1,1,1,0,0,1}, // 3
{0,1,1,0,0,1,1}, // 4
{1,0,1,1,0,1,1}, // 5
{1,0,1,1,1,1,1}, // 6
{1,1,1,0,0,0,0}, // 7
{1,1,1,1,1,1,1}, // 8
{1,1,1,1,0,1,1} // 9
};
void setup() {
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.show();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return;
}
int hour = timeinfo.tm_hour;
int minute = timeinfo.tm_min;
int d1 = hour / 10;
int d2 = hour % 10;
int d3 = minute / 10;
int d4 = minute % 10;
strip.clear();
drawDigit(d1, 0);
drawDigit(d2, 1);
drawDigit(d3, 2);
drawDigit(d4, 3);
drawColon(timeinfo.tm_sec % 2);
strip.show();
delay(200);
}
void drawDigit(int num, int position) {
int baseIndex = position * 14;
for (int seg = 0; seg < 7; seg++) {
if (digitMap[num][seg]) {
int ledIndex = baseIndex + (seg * 2);
strip.setPixelColor(ledIndex, strip.Color(255, 50, 0));
strip.setPixelColor(ledIndex + 1, strip.Color(255, 50, 0));
}
}
}
void drawColon(bool state) {
if (state) {
strip.setPixelColor(56, strip.Color(0, 0, 255));
strip.setPixelColor(57, strip.Color(0, 0, 255));
}
}Loading
xiao-esp32-c3
xiao-esp32-c3
FPS: 0
Power: 0.00W
Power: 0.00W