#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();
Particle.function("red", setRed);
}
void loop() {
uint32_t c1 = strip.Color(255, 255, 255); // white
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c1);
}
strip.show();
delay( 100 );
}
int setRed(String color){ //functions for particle.function start with an int and take only string commands
int rValue = color.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( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, red); // set a color
strip.show();
delay( 1000 );
}
uint32_t c2 = strip.Color(255, 255, 255); //turning off by removing color
for( int i = strip.numPixels(); i >-1; i-- ){
strip.setPixelColor(i, c2); // set a color
strip.show();
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!
You must login before you can post a comment. .