#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
strip.begin();
Particle.function("red", setRed);
Particle.function("blue", setBlue);
Particle.function("green", setGreen);
}
void loop() {
}
int setGreen(String value) {
int v = value.toInt();
uint32_t green = strip.Color(v, 0, 0);
int numPixels = strip.numPixels();
if (v >= 0 && v < 256) {
for( int i = 0; i < numPixels; i++ ){
strip.setPixelColor(i, green); // set a color
}
strip.show();
delay(500);
return 1;
} else {
return -1;
}
}
int setBlue(String value) {
int v = value.toInt();
uint32_t blue = strip.Color(0, 0, v);
int numPixels = strip.numPixels();
if (v >= 0 && v < 256) {
for( int i = 0; i < numPixels; i++ ){
strip.setPixelColor(i, blue); // set a color
}
strip.show();
delay(500);
return 1;
} else {
return -1;
}
}
int setRed(String value) {
int v = value.toInt();
uint32_t Red = strip.Color(0, v, 0);
int numPixels = strip.numPixels();
if (v >= 0 && v < 256) {
for( int i = 0; i < numPixels; i++ ){
strip.setPixelColor(i, Red); // set a color
}
strip.show();
delay(500);
return 1;
} else {
return -1;
}
}
Click to Expand