Back to Parent

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

#define PIXEL_PIN D2
#define PIXEL_COUNT 8 //for stick, 16 for ring
#define PIXEL_TYPE WS2812B //for 4pin neopixels, WS2812/WS2813 for 6pin

unsigned long redTimer = 0;

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

bool meetingTrigger = false;

int redValue = 10;
int greenValue = 10;
int blueValue = 10;

// this function automagically gets called upon a matching POST request
int IFTTT_Function1(String command){
    meetingTrigger = !meetingTrigger;
    redTimer = millis(); //in milliseconds, 1000 = 1sec
    if(command == "1"){
        meetingTrigger = !meetingTrigger;
        redTimer = millis(); //in milliseconds, 1000 = 1sec
    }
    if(meetingTrigger){
        return 1;
    }
    return 0;
}

void NeoPixelRedFade(bool fadeIn, unsigned long fadeTime){ //fade to/from white
    
    if(fadeIn && redValue < 255){//decrease r
        redValue = map(millis(), redTimer, redTimer + fadeTime, 10, 240);
        for(int i=0; i<strip.numPixels(); i++){
            strip.setPixelColor(i, redValue, 10, 10);
        }
    }
    else{//fade out, decrease r
        redValue = map(millis(), redTimer + fadeTime, redTimer + fadeTime + fadeTime, 240, 10);
        for(int i=0; i<strip.numPixels(); i++){
            strip.setPixelColor(i, redValue, 10, 10);
        }
        if(redValue == 10){
            meetingTrigger = false;
        }
    }
}
//------------------------------------------------------------------------
void setup() {
    
    //Neopixel
    strip.begin();
    strip.show();
    
    //Cloud Functions
    Particle.function("IFTTT1", IFTTT_Function1);
    //Colors used to debug LED values
    Particle.variable("Red Value", redValue);
    Particle.variable("Green Value", greenValue);
    Particle.variable("Blue Value", blueValue);
}
//------------------------------------------------------------------------
void loop() {
    unsigned long fadeTime = 900000;
    
    if(meetingTrigger){//fade to red if meeting trigger is true
        if(millis() < redTimer + fadeTime){ //1000ms * 60sec/min * 15min = 900,000, 1.5min for 90,000,
            NeoPixelRedFade(true, fadeTime);
        }else{ NeoPixelRedFade(false, fadeTime); }
    }else{//white
        redValue = 10;
        greenValue = 10;
        blueValue = 10;
        for(int i=0; i<strip.numPixels(); i++){
            strip.setPixelColor(i, redValue, greenValue, blueValue);
        }
    }
    strip.show();
    delay(1000);
}
Click to Expand

Content Rating

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

0