#include <FastLED.h>
// Define the number of LEDs
#define NUM_LEDS 448 // 16 * 28 = 448
#define DATA_PIN 13 // The data pin connected to the matrix
// Create an array to hold the LED data
CRGB leds[NUM_LEDS];
// Define the width and height of the matrix
const uint8_t kMatrixWidth = 28;
const uint8_t kMatrixHeight = 16;
// Function to convert x, y coordinates to an index in the LED array
uint16_t XY(uint8_t x, uint8_t y) {
uint16_t index;
if (y % 2 == 0) {
// Even rows run left to right
index = (y * kMatrixWidth) + x;
} else {
// Odd rows run right to left
index = (y * kMatrixWidth) + (kMatrixWidth - 1 - x);
}
return index;
}
void setup() {
// Initialize the LED array
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void loop() {
// Example: Draw a moving rainbow pattern
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = 0; y < kMatrixHeight; y++) {
// Calculate the hue based on the x and y positions
uint8_t hue = (x * 10) + (y * 10);
leds[XY(x, y)] = CHSV(hue, 255, 255);
}
}
FastLED.show();
delay(100);
// Move the rainbow pattern
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)].nscale8(250); // Dim the LEDs slightly
}
}
FastLED.show();
delay(100);
}