#include <FastLED.h>
#define WIDTH 16
#define HEIGHT 16
#define NUM_LEDS (WIDTH * HEIGHT)
CRGB leds[NUM_LEDS + 1];
CRGBPalette16 currentPalette = {
0xFFffff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
};
void setup() {
FastLED.addLeds<NEOPIXEL, 3>(leds, NUM_LEDS);
}
uint16_t XY(uint8_t x, uint8_t y) {
if (x >= WIDTH) return NUM_LEDS;
if (y >= HEIGHT) return NUM_LEDS;
return y * WIDTH + x;
}
void loop()
{
uint32_t ms = millis();
// draw the background animation, just like the XYmatrix example
uint32_t yHueDelta = (int32_t)sin16(ms * 11) * 3;
uint32_t xHueDelta = (int32_t)cos16(ms * 11) * 3;
uint32_t startHue = -128; // half the width of a single Palette16 colour, to centre the line
uint32_t lineStartHue = startHue - (HEIGHT + 1) * yHueDelta / 2;
for (byte y = 0; y < HEIGHT; y++) {
uint32_t pixelHue = lineStartHue - (WIDTH + 1) * xHueDelta / 2;
uint32_t xhd = xHueDelta;
for (byte x = 0; x < WIDTH; x++) {
leds[XY(x, y)] = ColorFromPalette(currentPalette, pixelHue >> 15, 255, LINEARBLEND);
pixelHue += xhd;
}
lineStartHue += yHueDelta;
}
FastLED.show();
}