#include <Adafruit_NeoPixel.h>
#define LED_PIN 5 // Data pin
#define LED_COUNT 20 // Number of LEDs
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Function to get rainbow color
uint32_t wheel(byte pos) {
if(pos < 85) {
return strip.Color(pos * 3, 255 - pos * 3, 0);
}
else if(pos < 170) {
pos -= 85;
return strip.Color(255 - pos * 3, 0, pos * 3);
}
else {
pos -= 170;
return strip.Color(0, pos * 3, 255 - pos * 3);
}
}
void setup() {
strip.begin();
strip.show();
}
void loop() {
int pos = random(0, 255); // pick random rainbow color
int led = random(0, LED_COUNT); // pick random LED
strip.clear();
strip.setPixelColor(led, wheel(pos)); // set random rainbow LED
strip.show();
delay(random(10, 30)); // fast strobe speed (10–30ms)
}