Back to Parent

// 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);

int durationFade = 1000*60*15;
long timeStart = -1; //The Action starts
bool timerStarted = false; //If the timer for fading has started 

void setup() {
    strip.begin ();
    strip.show();  
    
   
    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); 
            
            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(); 
    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!

0