// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D3
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
bool change = false;
unsigned long lastFade = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("change", change_light);
}
int change_light(String command)
{
int b = command.toInt();
if (b == 0){
return -1;
}
else{
change = true;
// uint32_t new_color = strip.Color(120, 0, 0);
// c = new_color;
return 1;
}
}
bool tored = false;
void loop() {
uint16_t i;
//sets color to white
if (change == false){
uint32_t color = strip.Color(100, 100, 100);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay( 100 );
}
}
else{
if (tored == false){
Particle.publish("here");
int r = 100;
int g = 100;
int b = 100;
uint32_t color = strip.Color(r, g, b);
for (int i =0; i<60; i++){
b = b - round(100/60);
g = g - round(100/60);
color = strip.Color(r, g, b);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
}
delay(1000);
}
tored = true;
change = true;
}
else{
Particle.publish("here");
int r = 100;
int g = 0;
int b = 0;
uint32_t color = strip.Color(r, g, b);
for (int i =0; i<60; i++){
b = b + round(100/60);
g = g + round(100/60);
color = strip.Color(r, g, b);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
}
delay(1000);
}
tored = false;
}
}
}
Click to Expand