Back to Parent

// This #include statement was automatically added by the Particle IDE.
#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();
    strip.show();
    Particle.function("tomato", setRed);
    Particle.function("spinach", setGreen);
    Particle.function("blueberry", setBlue);

}

void loop() {

}

int setRed(String f){ //functions for particle.function start with an int and take only string commands
  
        int rValue = f.toInt();  //first:convert string to number
        uint32_t red = strip.Color(rValue, 0, 0); //second: use the newly converted int to define color
    
        uint16_t i;
        for (i=0; i < strip.numPixels(); i++){
            strip.setPixelColor(i, red);
            strip.show(); 
        }
   
        delay(500);
    
        return 1;
    }



int setGreen(String f){ //functions for particle.function start with an int and take only string commands
  
    int gValue = f.toInt();  //first:convert string to number
    uint32_t green = strip.Color(0, gValue, 0); //second: use the newly converted int to define color
    
    uint16_t i;
    for (i=0; i < strip.numPixels(); i++){
        strip.setPixelColor(i, green);
        strip.show(); 
    }
   
    delay(500);
    
    return 1;
}

int setBlue(String f){ //functions for particle.function start with an int and take only string commands
  
    int bValue = f.toInt();  //first:convert string to number
    uint32_t blue = strip.Color(0, 0, bValue); //second: use the newly converted int to define color
    
    uint16_t i;
    for (i=0; i < strip.numPixels(); i++){
        strip.setPixelColor(i, blue);
        strip.show(); 
    }
   
    delay(500);
    
    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