// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
//Set pixel COUNT, PIN, and TYPE
#define PIXEL_COUNT 8
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int red = 25;
int green = 25;
int blue = 25;
int durationOfFade = 1000 * 60 * 15; //15 minutes
bool calendarAlert = false; //checkpoint for calendar alert
unsigned long lastUpdate;
unsigned long now = 0;
uint16_t i;
uint32_t cRed = strip.Color(25, 0, 0);
uint32_t cGreen = strip.Color(0, 25, 0);
uint32_t cBlue = strip.Color(0, 0, 25);
uint32_t cWhite = strip.Color(25, 25, 25);
void setup() {
strip.begin();
strip.show();
Particle.function("blue", blueControl);
Particle.function("red", redControl);
Particle.function("green", greenControl);
Particle.function("meetingAlert", meetingAlert);
for (i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i,cWhite);
strip.show();
}
}
void loop() {
if (calendarAlert == true) {
now = millis();
long timeElapsed = now - lastUpdate;
if (timeElapsed <= durationOfFade) {
int colorValue = map(timeElapsed, 0, durationOfFade, 0, 255);
int r = colorValue;
int g = 0;
int b = 0;
for (i=0; i<strip.numPixels(); i++){
strip.setPixelColor(i,r,g,b);
}
strip.show();
}
else {
calendarAlert = false;
Particle.publish("MeetingStarted-FadingToWhite");
}
}
else {
now = millis();
long timeElapsed = now - lastUpdate;
if ((timeElapsed >= durationOfFade) && (timeElapsed <= 2*durationOfFade)) {
int colorValue = map(timeElapsed, 0, 2*durationOfFade, 0, 255);
int r = colorValue;
int g = colorValue;
int b = colorValue;
if (r>25) {
for (i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i,(255-r),g,b);
}
strip.show();
}
}
}
}
//IFTTT function
int meetingAlert(String command) {
if(command == "True") {
calendarAlert = true;
lastUpdate = millis();
Particle.publish("MeetingStarting-FadingToRed");
return 1;
}
return -1;
}
int blueControl(String command) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, cBlue);
strip.show();
delay( 0 );
}
return 1;
}
int redControl(String command) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, cRed);
strip.show();
delay( 0 );
}
return 1;
}
int greenControl(String command) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, cGreen);
strip.show();
delay( 0 );
}
return 1;
}
Click to Expand