#include <FastLED.h>
#define LED_PIN 3
#define LED_W 8
#define LED_H 8
#define NUM_LEDS (LED_W * LED_H)
CRGB leds[NUM_LEDS];
uint8_t frame[LED_H][LED_W]; // indexed buffer
int8_t scrollX = 0;
uint8_t hueOffset = 0;
// ================= PALETTE =================
DEFINE_GRADIENT_PALETTE(wave_gp) {
0, 0, 0, 64,
64, 0, 128, 255,
128, 0, 255, 128,
192, 255, 255, 0,
255, 255, 0, 0
};
CRGBPalette16 palette = wave_gp;
// ================= MATRIX MAP =================
uint16_t XY(uint8_t x, uint8_t y) {
if (y & 1) {
return (y * LED_W) + (LED_W - 1 - x); // serpentine
} else {
return (y * LED_W) + x;
}
}
// ================= PATTERN =================
void buildPattern() {
for (uint8_t y = 0; y < LED_H; y++) {
for (uint8_t x = 0; x < LED_W; x++) {
frame[y][x] = (x * 32) + (y * 16);
}
}
}
// ================= RENDER =================
void render() {
for (uint8_t y = 0; y < LED_H; y++) {
for (uint8_t x = 0; x < LED_W; x++) {
uint8_t sx = (x + scrollX) % LED_W;
uint8_t idx = frame[y][sx] + hueOffset;
leds[XY(x, y)] = ColorFromPalette(
palette,
idx,
200,
LINEARBLEND
);
}
}
FastLED.show();
}
// ================= SETUP =================
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(120);
buildPattern();
}
// ================= LOOP =================
void loop() {
scrollX = (scrollX + 1) % LED_W;
hueOffset++;
render();
delay(40);
}