Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN A5
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int durationOfFade = 1000 * 60 * 0.5;
long timeStartedAt = 0;
bool timeStarter = false;



void setup() {
    
    strip.begin();
    strip.show();
    Particle.function("fadeUp", HandleFadeUp);
    
    Serial.begin (9600);
}

void loop() {

    if (timeStarter == true){
        
        long timeNow = millis();
        long timeElapsed = timeNow - timeStartedAt;
        int r = 255;
        int g = 255;
        int b = 255;
        
        if (timeElapsed < durationOfFade){
            int colorValue = map(timeElapsed, 0, durationOfFade, 0, 255);
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, r, g - colorValue, b - colorValue);
            }
            strip.show();
            delay (10);
        }else if ( (durationOfFade - timeElapsed) < 1000*10){

            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 255, 0, 0);
            }
            strip.show();
            delay (100);   
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 0, 0, 0);
            }
            strip.show();
            delay (100);     
        }
      
    }
    
}

int HandleFadeUp (String cmd){
    

    timeStartedAt = millis();
    timeStarter = true;   
    
    return 1;
    
    if (cmd == "off"){
        timeStarter = false;
        for (int i = 0; i < strip.numPixels(); i++){
            strip.setPixelColor (i, 0, 0, 0);
            }
        strip.show();
        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