#include <Adafruit_NeoPixel.h>
#define PIN 8
#define NUMPIXELS 24
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 100 ;// delay for half a second
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Forward chase
for(int i=0; i<NUMPIXELS; i++) {
colorWipe(strip.Color(255, 0, 0), delayval); // Red
colorWipe(strip.Color(255, 127, 0), delayval); // Orange
colorWipe(strip.Color(255, 255, 0), delayval); // Yellow
colorWipe(strip.Color(0, 255, 0), delayval); // Green
colorWipe(strip.Color(0, 0, 255), delayval); // Blue
colorWipe(strip.Color(75, 0, 130), delayval); // Indigo
colorWipe(strip.Color(143, 0, 255), delayval); // Violet
}
// Backward chase
for(int i=NUMPIXELS-1; i>=0; i--) {
colorWipe(strip.Color(143, 0, 255), delayval); // Violet
colorWipe(strip.Color(75, 0, 130), delayval); // Indigo
colorWipe(strip.Color(0, 0, 255), delayval); // Blue
colorWipe(strip.Color(0, 255, 0), delayval); // Green
colorWipe(strip.Color(255, 255, 0), delayval); // Yellow
colorWipe(strip.Color(255, 127, 0), delayval); // Orange
colorWipe(strip.Color(255, 0, 0), delayval); // Red
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}