#include <Adafruit_NeoPixel.h>
#define PIN 2 // Define the pin where your NeoPixel matrix is connected
#define WIDTH 32
#define HEIGHT 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(WIDTH * HEIGHT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
for (int row = 0; row < HEIGHT; row++) {
fibonacciChase(row);
}
}
void fibonacciChase(int row) {
int a = 0, b = 1, fib = 0;
uint32_t color = strip.Color(random(0, 256), random(0, 256), random(0, 256)); // Generate random color
for (int i = 0; i < WIDTH; i++) {
if (i == fib) {
strip.setPixelColor(row * WIDTH + i, color);
fib = a + b;
a = b;
b = fib;
} else {
strip.setPixelColor(row * WIDTH + i, 0); // Turn off other pixels
}
}
strip.show();
delay(200);
// Reverse chase
for (int i = WIDTH - 1; i >= 0; i--) {
if (i == fib) {
strip.setPixelColor(row * WIDTH + i, color);
fib = a - b;
a = b;
b = fib;
} else {
strip.setPixelColor(row * WIDTH + i, 0);
}
}
strip.show();
delay(200);
}