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);

void setup(){
    
    strip.begin();
    // Initialize all pixels to "off"
    strip.show(); 
    
    //Register particle function
    Particle.function("Set to Red", setRed);
    Particle.function("Set to Green", setGreen);
    Particle.function("set to Blue", setBlue);

}


void loop(){
    
}


int setRed(String command){
    
    uint16_t i;
    
    // convert the input command into int 
    // and store the value into the variable rValue
    int rValue = command.toInt();
    
    uint32_t red = strip.Color(rValue, 0, 0);
    
    for(i=0; i < strip.numPixels(); i++){
        strip.setPixelColor(i, red);
        strip.show();
    }
    delay(200);
    
    return 1;
}

int setGreen(String command){
    
    uint16_t i;
    // convert t a number gValue
    // and store the value into the variable gValue
    int gValue = command.toInt();
    // use gValue to define the green color
    uint32_t green = strip.Color(0, gValue, 0);
    
    for(i=0; i < strip.numPixels(); i++){
        strip.setPixelColor(i, green);
        strip.show();
    }
    delay(200);
    
    return 1;

}


int setBlue(String command){
    
    uint16_t i;
    // convert t a number bValue
    // and store the value into the variable bValue
    int bValue = command.toInt();
    // use bValue to define the blue color
    uint32_t blue = strip.Color(0, 0, bValue);
    
    for(i=0; i < strip.numPixels(); i++){
        strip.setPixelColor(i, blue);
        strip.show();
    }
    delay(200);
    
    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