#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() {
// Blink the first row in rainbow colors
for (int i = 0; i < WIDTH; i++) {
strip.setPixelColor(i, Wheel((i * 256 / WIDTH) & 255));
}
strip.show();
delay(200);
clearRow(0);
strip.show();
delay(200);
// Fibonacci chase for the rest of the rows
for (int row = 1; 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);
}
void clearRow(int row) {
for (int i = 0; i < WIDTH; i++) {
strip.setPixelColor(row * WIDTH + i, 0); // Turn off all pixels in the row
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}