#include <Adafruit_NeoPixel.h>
// Pin where the NeoPixel strip is connected
#define PIN 3
// Number of LEDs in the strip
#define NUM_LEDS 60
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Array to store Fibonacci positions
int fib[] = {0, 1, 2, 3, 5, 8, 13, 21, 34, 55};
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbowChase();
}
void rainbowChase() {
static int direction = 1;
static int position = 0;
for (int i = 0; i < sizeof(fib)/sizeof(fib[0]); i++) {
int idx = fib[i] + position;
if (idx < NUM_LEDS) {
strip.setPixelColor(idx, Wheel((idx * 256 / NUM_LEDS) & 255));
}
}
strip.show();
delay(100);
// Clear previous pixels
for (int i = 0; i < sizeof(fib)/sizeof(fib[0]); i++) {
int idx = fib[i] + position;
if (idx < NUM_LEDS) {
strip.setPixelColor(idx, 0);
}
}
// Change direction at the end of the strip
if (position == 0) direction = 1;
if (position == (NUM_LEDS - fib[sizeof(fib)/sizeof(fib[0]) - 1] - 1)) direction = -1;
position += direction;
}
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);
}
}