#include <FastLED.h>
// ================= HARDWARE CONFIGURATION =================
#define LED_PIN 12 // Try other pins: 6, 5, 3 if 12 doesn't work
#define COLOR_ORDER GRB // Try RGB if colors are wrong
#define CHIPSET WS2812 // Try WS2811, NEOPIXEL if this doesn't work
#define BRIGHTNESS 100 // Start with lower brightness for testing
// Matrix dimensions
const uint8_t matrixWidth = 32;
const uint8_t matrixHeight = 16;
#define NUM_LEDS (matrixWidth * matrixHeight)
CRGB leds[NUM_LEDS];
// ================= TEST PATTERNS =================
void testSingleLED() {
// Test 1: Light up first LED only
FastLED.clear();
leds[0] = CRGB::Red;
FastLED.show();
Serial.println("Testing LED 0 - Should be red");
delay(2000);
}
void testFirstRow() {
// Test 2: Light up first 10 LEDs of first row
FastLED.clear();
for(int i = 0; i < 10; i++) {
leds[i] = CRGB::Green;
}
FastLED.show();
Serial.println("Testing first 10 LEDs - Should be green");
delay(2000);
}
void testAllRed() {
// Test 3: All LEDs red
FastLED.clear();
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
Serial.println("All LEDs red");
delay(2000);
}
void testAllGreen() {
// Test 4: All LEDs green
FastLED.clear();
fill_solid(leds, NUM_LEDS, CRGB::Green);
FastLED.show();
Serial.println("All LEDs green");
delay(2000);
}
void testAllBlue() {
// Test 5: All LEDs blue
FastLED.clear();
fill_solid(leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
Serial.println("All LEDs blue");
delay(2000);
}
void testRainbow() {
// Test 6: Rainbow pattern
fill_rainbow(leds, NUM_LEDS, 0, 255/NUM_LEDS);
FastLED.show();
Serial.println("Rainbow pattern");
delay(3000);
}
void testSerpentine() {
// Test 7: Test serpentine pattern to verify wiring
FastLED.clear();
// Draw a diagonal line
for(int i = 0; i < 16; i++) {
int x = i;
int y = i;
if (y < matrixHeight && x < matrixWidth) {
int index;
if (y % 2 == 0) {
// Even row: left to right
index = y * matrixWidth + x;
} else {
// Odd row: right to left
index = y * matrixWidth + (matrixWidth - 1 - x);
}
leds[index] = CRGB::Yellow;
}
}
// Draw another diagonal
for(int i = 0; i < 16; i++) {
int x = 31 - i;
int y = i;
if (y < matrixHeight && x >= 0) {
int index;
if (y % 2 == 0) {
index = y * matrixWidth + x;
} else {
index = y * matrixWidth + (matrixWidth - 1 - x);
}
leds[index] = CRGB::Cyan;
}
}
FastLED.show();
Serial.println("Serpentine test - Should see two diagonal lines");
delay(4000);
}
// ================= SIMPLE XY FUNCTION =================
uint16_t XY(uint8_t x, uint8_t y) {
if (x >= matrixWidth || y >= matrixHeight) return NUM_LEDS;
// Simple row-major (no serpentine)
return y * matrixWidth + x;
}
void testMatrixPattern() {
// Test 8: Draw borders and center dot
FastLED.clear();
// Draw border
for(int x = 0; x < matrixWidth; x++) {
leds[XY(x, 0)] = CRGB::Red; // Top border
leds[XY(x, matrixHeight-1)] = CRGB::Red; // Bottom border
}
for(int y = 0; y < matrixHeight; y++) {
leds[XY(0, y)] = CRGB::Red; // Left border
leds[XY(matrixWidth-1, y)] = CRGB::Red; // Right border
}
// Draw center dot
leds[XY(15, 7)] = CRGB::Green;
leds[XY(16, 7)] = CRGB::Green;
leds[XY(15, 8)] = CRGB::Green;
leds[XY(16, 8)] = CRGB::Green;
FastLED.show();
Serial.println("Border test - Should see red border and green center");
delay(4000);
}
// ================= COUNTDOWN TEST =================
void testCountdownDisplay() {
// Test 9: Display a simple countdown
for(int num = 5; num >= 0; num--) {
FastLED.clear();
// Simple number display
int startX = 13; // Rough center for 1-2 digit numbers
int startY = 5;
// Very simple number drawing (just for testing)
if(num == 0) {
// Draw a simple 0
for(int x = 0; x < 5; x++) {
leds[XY(startX + x, startY)] = CRGB::Red;
leds[XY(startX + x, startY + 5)] = CRGB::Red;
}
for(int y = 0; y < 6; y++) {
leds[XY(startX, startY + y)] = CRGB::Red;
leds[XY(startX + 4, startY + y)] = CRGB::Red;
}
} else {
// Draw simple number
for(int y = 0; y < 6; y++) {
leds[XY(startX + 2, startY + y)] = CRGB::Red;
}
}
FastLED.show();
Serial.print("Testing countdown: ");
Serial.println(num);
delay(1000);
}
}
// ================= SETUP =================
void setup() {
Serial.begin(9600);
Serial.println("\n\n=== 16x32 LED Matrix Tester ===");
Serial.println("Running diagnostic tests...\n");
// Initialize LEDs
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
// Quick flash to show startup
FastLED.clear();
FastLED.show();
delay(500);
// Run all tests
Serial.println("Test 1: Single LED");
testSingleLED();
Serial.println("Test 2: First 10 LEDs");
testFirstRow();
Serial.println("Test 3: All Red");
testAllRed();
Serial.println("Test 4: All Green");
testAllGreen();
Serial.println("Test 5: All Blue");
testAllBlue();
Serial.println("Test 6: Rainbow");
testRainbow();
Serial.println("Test 7: Serpentine Pattern");
testSerpentine();
Serial.println("Test 8: Matrix Border");
testMatrixPattern();
Serial.println("Test 9: Simple Countdown");
testCountdownDisplay();
Serial.println("\n=== Tests Complete ===");
Serial.println("\nIf you saw patterns, your matrix works!");
Serial.println("Now try the original countdown code again.");
Serial.println("\nIf you saw NOTHING, check:");
Serial.println("1. Power supply (5V, sufficient amps)");
Serial.println("2. Wiring connections");
Serial.println("3. Data pin (try pin 6 instead of 12)");
Serial.println("4. Ground connections");
Serial.println("5. LED type in code (WS2812 vs WS2811)");
}
void loop() {
// After tests, cycle through colors slowly
static int hue = 0;
fill_rainbow(leds, NUM_LEDS, hue++, 10);
FastLED.show();
delay(50);
}