#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <Adafruit_NeoPixel.h>
#include <TimeLib.h>
// ====== WiFi Credentials ======
const char* ssid = "Airtel_arvi_6035";
const char* password = "air262829";
// ====== NeoPixel Matrix Config ======
#define LED_PIN 8 // GPIO pin connected to NeoPixel DIN
#define LED_WIDTH 32
#define LED_HEIGHT 8
#define NUMPIXELS (LED_WIDTH * LED_HEIGHT)
Adafruit_NeoPixel matrix(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
// ====== NTP Client ======
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000);
// 19800 seconds = +5:30 offset for IST
// ====== Matrix Mapping (serpentine layout assumed) ======
int XY(int x, int y) {
if (y % 2 == 0) {
return y * LED_WIDTH + x;
} else {
return y * LED_WIDTH + (LED_WIDTH - 1 - x);
}
}
// ====== Draw Digit (simple 5x7 font) ======
const byte font5x7[][5] = {
{0x7E,0x81,0x81,0x81,0x7E}, // 0
{0x00,0x82,0xFF,0x80,0x00}, // 1
{0xE2,0x91,0x91,0x91,0x8E}, // 2
{0x42,0x89,0x89,0x89,0x76}, // 3
{0x1C,0x12,0x11,0xFF,0x10}, // 4
{0x4F,0x89,0x89,0x89,0x71}, // 5
{0x7E,0x89,0x89,0x89,0x72}, // 6
{0x01,0xF1,0x09,0x05,0x03}, // 7
{0x76,0x89,0x89,0x89,0x76}, // 8
{0x4E,0x91,0x91,0x91,0x7E} // 9
};
void drawDigit(int digit, int xOffset, int yOffset, uint32_t color) {
for (int col = 0; col < 5; col++) {
byte line = font5x7[digit][col];
for (int row = 0; row < 7; row++) {
if (line & (1 << row)) {
int px = xOffset + col;
int py = yOffset + row;
if (px >= 0 && px < LED_WIDTH && py >= 0 && py < LED_HEIGHT) {
matrix.setPixelColor(XY(px, py), color);
}
}
}
}
}
// ====== Setup ======
void setup() {
Serial.begin(115200);
matrix.begin();
matrix.clear();
matrix.show();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
timeClient.begin();
}
// ====== Loop ======
void loop() {
timeClient.update();
int hours = timeClient.getHours();
int minutes = timeClient.getMinutes();
matrix.clear();
// Draw HH:MM
drawDigit(hours / 10, 0, 0, matrix.Color(0, 255, 0));
drawDigit(hours % 10, 6, 0, matrix.Color(0, 255, 0));
// Colon
matrix.setPixelColor(XY(12, 2), matrix.Color(255, 0, 0));
matrix.setPixelColor(XY(12, 4), matrix.Color(255, 0, 0));
drawDigit(minutes / 10, 15, 0, matrix.Color(0, 0, 255));
drawDigit(minutes % 10, 21, 0, matrix.Color(0, 0, 255));
matrix.show();
delay(1000);
}