#include <Adafruit_NeoPixel.h>
#define LED_PIN 5
#define LED_COUNT 256
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
class Animation {
public:
struct Frame {
uint16_t index;
uint32_t color;
};
Frame* frames;
size_t frameCount;
Animation(Frame* f, size_t count) : frames(f), frameCount(count) {}
void play() {
strip.clear(); // Clear all LEDs before displaying the next animation
for (size_t i = 0; i < frameCount; ++i) {
strip.setPixelColor(frames[i].index, frames[i].color);
}
strip.show();
}
void clearAnimation(int delayTime) {
for (size_t i = 0; i < frameCount; ++i) {
strip.setPixelColor(frames[i].index, 0); // Set to black (off)
}
strip.show();
delay(delayTime);
}
};
// Define animations as shown in your original code...
Animation::Frame sequence1[] = {{17, strip.Color(255, 0, 0)}, {33, strip.Color(255, 0, 0)}, {49, strip.Color(255, 0, 0)}, {65, strip.Color(255, 0, 0)}, {81, strip.Color(255, 0, 0)}, {82, strip.Color(255, 0, 0)}, {83, strip.Color(255, 0, 0)}};
Animation::Frame sequence2[] = {{21, strip.Color(0, 255, 0)}, {22, strip.Color(0, 255, 0)}, {36, strip.Color(0, 255, 0)}, {39, strip.Color(0, 255, 0)}, {52, strip.Color(0, 255, 0)}, {55, strip.Color(0, 255, 0)}, {68, strip.Color(0, 255, 0)}, {71, strip.Color(0, 255, 0)}, {85, strip.Color(0, 255, 0)}, {86, strip.Color(0, 255, 0)}};
Animation::Frame sequence3[] = {{24, strip.Color(0, 0, 255)}, {27, strip.Color(0, 0, 255)}, {40, strip.Color(0, 0, 255)}, {43, strip.Color(0, 0, 255)}, {56, strip.Color(0, 0, 255)}, {59, strip.Color(0, 0, 255)}, {72, strip.Color(0, 0, 255)}, {75, strip.Color(0, 0, 255)}, {89, strip.Color(0, 0, 255)}, {90, strip.Color(0, 0, 255)}};
Animation::Frame sequence4[] = {{28, strip.Color(255, 0, 255)}, {29, strip.Color(255, 0, 255)}, {30, strip.Color(255, 0, 255)}, {44, strip.Color(255, 0, 255)}, {60, strip.Color(255, 0, 255)}, {61, strip.Color(255, 0, 255)}, {62, strip.Color(255, 0, 255)}, {76, strip.Color(255, 0, 255)}, {92, strip.Color(255, 0, 255)}, {93, strip.Color(255, 0, 255)}, {94, strip.Color(255, 0, 255)}};
Animation animation1(sequence1, sizeof(sequence1) / sizeof(sequence1[0]));
Animation animation2(sequence2, sizeof(sequence2) / sizeof(sequence2[0]));
Animation animation3(sequence3, sizeof(sequence3) / sizeof(sequence3[0]));
Animation animation4(sequence4, sizeof(sequence4) / sizeof(sequence4[0]));
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
animation1.play();
delay(500);
animation2.play();
delay(500);
animation3.play();
delay(500);
animation4.play();
delay(500);
}