// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
long timeAtParticleFuction = 0;
long turnOffAfter = 15*60*1000;
bool lightOn = false;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("turnOn", turnOn );
}
int turnOn(String command)
{
lightOn = true;
timeAtParticleFuction = millis();
return 0;
}
void loop() {
uint16_t i;
long timeNow = millis();
if(lightOn == true){
for(i=0; i< strip.numPixels(); i++) {
//turn on the pixel one by one, as blue
strip.setPixelColor(i, 0, 0, 255); //blue
strip.show();
delay(100);
strip.setPixelColor(i, 0, 0, 0);
strip.show();
delay(100);
}
// turn off all the light when 0 min left
if (timeAtParticleFuction + turnOffAfter < timeNow){
lightOn = false;
}
}else{
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
}
}
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. .