I found quite a lot of tutorials on using the Ulanzi TC001 with a firmware like .
Install the ESP32 boards in the board manager.
#include <FastLED.h>
#define NUM_LEDS 256
#define DATA_PIN 32
CRGB leds[NUM_LEDS];
void setup() {
pinMode(15, INPUT_PULLDOWN); //Stops the High pitch noise!
pinMode(27, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
FastLED.show();
delay(50);
leds[i] = CRGB::Black;
}
}
To fix this, we can use a helper function function "setLED" which will allow us to set any pixel simply by referring to its X,Y position, and will deal with the alternating direction of the rows.
void setLED(int x, int y, CRGB color) {
if (x < 0 || x >= MATRIX_WIDTH || y < 0 || y >= MATRIX_HEIGHT) return;
int index = (y % 2 == 0) ? y * MATRIX_WIDTH + x : (y + 1) * MATRIX_WIDTH - 1 - x;
leds[index] = color;
}
The following code will allow you to display the time!
#include <FastLED.h>
#include <WiFi.h>
#include <time.h>
#define NUM_LEDS 256
#define DATA_PIN 32
#define MATRIX_WIDTH 32
#define MATRIX_HEIGHT 8
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600;
CRGB leds[NUM_LEDS];
// 3x5 font for digits
const uint8_t digits[10][5] = {
{0b111, 0b101, 0b101, 0b101, 0b111}, // 0
{0b010, 0b110, 0b010, 0b010, 0b111}, // 1
{0b111, 0b001, 0b111, 0b100, 0b111}, // 2
{0b111, 0b001, 0b111, 0b001, 0b111}, // 3
{0b101, 0b101, 0b111, 0b001, 0b001}, // 4
{0b111, 0b100, 0b111, 0b001, 0b111}, // 5
{0b111, 0b100, 0b111, 0b101, 0b111}, // 6
{0b111, 0b001, 0b010, 0b010, 0b010}, // 7
{0b111, 0b101, 0b111, 0b101, 0b111}, // 8
{0b111, 0b101, 0b111, 0b001, 0b111} // 9
};
void setup() {
Serial.begin(115200);
pinMode(15, INPUT_PULLDOWN);
pinMode(27, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void setLED(int x, int y, CRGB color) {
if (x < 0 || x >= MATRIX_WIDTH || y < 0 || y >= MATRIX_HEIGHT) return;
int index = (y % 2 == 0) ? y * MATRIX_WIDTH + x : (y + 1) * MATRIX_WIDTH - 1 - x;
leds[index] = color;
}
void drawDigit(int x, int y, int digit, CRGB color) {
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 3; col++) {
if (digits[digit][row] & (1 << (2 - col))) {
setLED(x + col, y + row, color);
}
}
}
}
void drawTime(int hours, int minutes, int seconds, CRGB color) {
drawDigit(0, 1, hours / 10, color);
drawDigit(4, 1, hours % 10, color);
setLED(8, 2, color);
setLED(8, 4, color);
drawDigit(10, 1, minutes / 10, color);
drawDigit(14, 1, minutes % 10, color);
setLED(18, 2, color);
setLED(18, 4, color);
drawDigit(20, 1, seconds / 10, color);
drawDigit(24, 1, seconds % 10, color);
}
void loop() {
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
FastLED.clear();
drawTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, CRGB::White);
FastLED.show();
delay(1000);
}
SOCIAL SHARE CARD GENERATOR