Back to Parent

#include <neopixel.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
    strip.begin();
    
    uint32_t blue = strip.Color(0, 0, 255);
    uint32_t red = strip.Color(255, 0, 0);
    uint32_t green = strip.Color(0, 255, 0);
    uint32_t white = strip.Color(255, 255, 255);
    uint32_t black = strip.Color(0, 0, 0);
    
    uint32_t colors[] = {blue, red, green, white};
    
    int numPixels = strip.numPixels();
    
    for (int j = 0; j < 4; j++) {
    
        for( int i = 0; i < numPixels; i++ ){
            strip.setPixelColor(i, colors[j]); // set a color 
                
        }
        
        strip.show(); // set updates to the strip
        delay(1500); 
        
        for( int i = numPixels; i >= 0; i-- ) {
            strip.setPixelColor(i, black); // remove the color
        }   
        strip.show();
        delay(500);
    }
    
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0