#include <Adafruit_NeoPixel.h>
#define LED_PIN 2
#define LED_COUNT 60
Adafruit_NeoPixel pixels(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
}
void loop() {
rainbowChaseClockwise(20, 50); // Change the values as per your preference
rainbowChaseAnticlockwise(20, 50); // Change the values as per your preference
}
void rainbowChaseClockwise(int delayTime, int trailLength) {
for (int j = 0; j < 256; j++) {
for (int i = 0; i < pixels.numPixels() + trailLength; i++) {
pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
pixels.show();
delay(delayTime);
if (i >= trailLength) {
pixels.setPixelColor(i - trailLength, 0);
}
}
}
}
void rainbowChaseAnticlockwise(int delayTime, int trailLength) {
for (int j = 0; j < 256; j++) {
for (int i = pixels.numPixels() - 1; i >= -trailLength; i--) {
int pixelIndex = i;
if (i < 0) {
pixelIndex = pixels.numPixels() + i; // Wrap around to the last pixel
}
pixels.setPixelColor(pixelIndex, Wheel(((pixelIndex * 256 / pixels.numPixels()) + j) & 255));
pixels.show();
delay(delayTime);
if (i >= -trailLength) {
int prevPixelIndex = i + trailLength;
if (prevPixelIndex < 0) {
prevPixelIndex = pixels.numPixels() + prevPixelIndex; // Wrap around to the last pixel
}
pixels.setPixelColor(prevPixelIndex, 0);
}
}
}
}
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}