Back to Parent

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

// 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 8
#define PIXEL_TYPE WS2812

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

int r = 255;    // set rgb value to make changing color more convenient
int g = 255;
int b = 255;
int remindBefore = 5;                          // set notification trigger time (how many minutes before the meeting)
int fadeInPeriod = remindBefore * 60 * 1000;
int fadeOutPeriod = remindBefore * 60 * 1000;
unsigned long lastFade = 0;     //set timer
unsigned long now = millis();
bool fadeIn = FALSE;
bool fadeOut = FALSE;

void setup() {
    strip.begin();
    // start with white 
    uint32_t c = strip.Color(255,255,255); // Pure white
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
        }
    strip.show();
    // remind function
    Particle.function("alert", turnRed);
}

int turnRed(String command)
{
    fadeIn = TRUE;
    return 1;

}

void loop() {
    if (fadeIn == TRUE){
    while (g > 0 && b > 0){
        if ((now - lastFade) >= fadeInPeriod / 255){   // the g/b value will decrease gradually to 0 over fadeInPeriod
            g--;
            b--;
            lastFade = now;
        }
        uint32_t c = strip.Color(r,g,b);     // update the neopixels after finishing the change of rgb value 
        for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
        strip.show();
       }
        now = millis();  // now gets updated after each g&b update
    }
    fadeIn = FALSE;
    fadeOut = TRUE;
}

    if (fadeOut == TRUE){
        lastFade = 0;
        while (g < 255 && b < 255){
            if ((now - lastFade) >= fadeOutPeriod / 255){   // the g/b value will decrease gradually to 0 over fadeInPeriod
               g++;
               b++;
               lastFade = now;
           }
        uint32_t c = strip.Color(r,g,b);     // update the neopixels after finishing the change of rgb value 
        for( int i = 0; i < strip.numPixels(); i++ ){
            strip.setPixelColor(i, c); // set a color 
            strip.show();
        }
        now = millis(); 
        }
    }


}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0