#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 256
#define COLOR_DEPTH 16 // Number of colors in the palette
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
// Define the pattern (1 byte per LED: index into the palette)
const uint8_t packedPattern[NUM_LEDS / 2] PROGMEM = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
};
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
// Initialize the palette with predefined colors
currentPalette = CRGBPalette16(
CRGB::Black, CRGB::White, CRGB::Red, CRGB::Lime,
CRGB::Blue, CRGB::Yellow, CRGB::Cyan, CRGB::Magenta,
CRGB::Silver,CRGB::Gray, CRGB::Maroon,CRGB::Olive,
CRGB::Green, CRGB::Purple, CRGB::Teal, CRGB::Navy
);
}
void loop() {
renderPattern();
FastLED.show();
delay(1000); // Pause for 1 second
}
// Function to render the pattern
void renderPattern() {
for (uint16_t i = 0; i < NUM_LEDS / 2; i++) {
// Read a single byte from the packed pattern
uint8_t packedByte = pgm_read_byte(&packedPattern[i]);
// Extract the high nibble (first LED's color index)
uint8_t highNibble = (packedByte >> 4) & 0x0F;
leds[i * 2] = ColorFromPalette(currentPalette, highNibble * (255 / (COLOR_DEPTH - 1)));
// Extract the low nibble (second LED's color index)
uint8_t lowNibble = packedByte & 0x0F;
leds[i * 2 + 1] = ColorFromPalette(currentPalette, lowNibble * (255 / (COLOR_DEPTH - 1)));
}
}