// 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 is the class, or library that is called, for the variable ‘strip’ (similar to int, bool)
Adafruit_NeoPixel strip = Adafruit_NeoPixel (PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int durationFade = 1000*60*15;
long timeStart = -1; //when the action starts
bool timerStarted = false; //whether the timer for fading has started or not
void setup() {
strip.begin ();
strip.show();
//Particle.function("eventLightUp",handleHandleLightUp);
Particle.function("fadeUp", handleFadeUp);
}
void loop() {
if (timerStarted==true){
long timeNow = millis();
long timeElapsed = timeNow - timeStart;
if(timeElapsed < durationFade){
int colorValue = map(timeElapsed, 0, durationFade, 0, 255); //scales timeElapsed from the range 0 to durationFade, to 0 to 255
int r=colorValue;
int g=0;
int b=0;
for(int i=0; i<strip.numPixels();i++){
strip.setPixelColor(i,r,g,b);
}
strip.show();
}else{
timerStarted = false;
for(int k=256; k>=0; k--){
for(int i=0;i<strip.numPixels();i++){
strip.setPixelColor(i,0,0,250);
strip.show();
delay(10);
}
}
}
}
else{
for(int i=0;i<strip.numPixels();i++){
strip.setPixelColor(i,10,10,10);
strip.show();
delay(10);
}
}
}
int handleFadeUp(String cmd){
timeStart = millis(); //storing the value at which the particlefunction was triggered
timerStarted =true;
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. .