Back to Parent

// EXCERCISE 4: Inputting RGB value for Neopixel

// This #include statement was automatically added by the Particle IDE.
#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);
int colorFunc(const char *args);

void setup() {
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    Particle.function("colorFunc", colorFunc);
}

void loop() {
    
}

int colorFunc(const char *args) {
    
    int R, G, B;
    sscanf(args, "%d,%d,%d", &R, &G, &B);

    uint16_t i;
    uint32_t c = strip.Color(R, G, B);
        
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
	    strip.show();
	    delay( 100 );
    }
    delay( 1000 );
    return 1;
}
Click to Expand

Content Rating

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

0