Back to Parent

#include "neopixel.h"

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// store rgb values in global variables
int r = 0; 
int g = 0;
int b = 0;

// store the name of the color in a global variable
String npColor;

/////////// Ambient Orb/////////////////
void setup(){
    
    strip.begin();
    // initialize all pixels to "off"
    strip.show();
    
    Particle.function("Set color", setColor);
    
    Particle.variable("brightness", brightness);
    Particle.variable("Neopixel Color", npColor);

    // set default color
    setColor("white");
    
}

void loop(){

}

// function to set color to white or red
int setColor(String command){
    
    // update the stored neopixel color value
    npColor = command;
    
    uint16_t i;
    uint32_t white = strip.Color(100, 100, 100);
    uint32_t red = strip.Color(100, 0, 0);
    
    if (npColor  == "white"){
        
        // set rgb values all to 100 (white)
        r = 100;
        g = 100;
        b = 100;
        
        // turn on neopixel using the rgb values of white
        for(i = 0; i < strip.numPixels(); i++){
            strip.setPixelColor(i, r, g, b);
            strip.show();
        }
        delay(100);
        return 1;
        } else if (npColor == "red"){
            // set r=100, g & b = 0 (red)
            r = 100;
            g = 0;
            b = 0;
            
            // turn on neopixel using the rgb values of red
            for(i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor(i, r, g, b);
                strip.show();
            }
            delay(100);
            return 1;
            } else {
              // if the command is neither white or red, return -1 
                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