// 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 cRed = 25; //to track the value of Red color
int cGreen = 25; //to track the value of Green color
int cBlue = 25; //to track the value of Blue color
bool calAlert_Status = false; //to check if the calender alert occured
unsigned long lastUpdate; //to check track the time usin millis()
unsigned long now =0; //to check track the time usin millis()
void setup() {
strip.begin();
strip.show(); //Initialize all pixels to 'off'
//Particle function on cloud
Particle.function("Cal_Alert", setCalAlert);
//Switch on each pixel all at once with cool white color
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, cRed, cGreen, cBlue);
}
strip.show();
}
void loop() {
if (calAlert_Status == true){
//Fade to red
now = millis();
if ((now - lastUpdate) <= 900000){
cRed = map((now - lastUpdate), 0, 900000, 20, 255);
cGreen = map((now - lastUpdate), 0, 900000, 0, 25);
cBlue = map((now - lastUpdate), 0, 900000, 0, 25);
if(cGreen<0){
cGreen = 0;
cBlue = 0;
}
if (cRed <= 255) {
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, cRed, (25-cGreen), (25-cBlue));
}
strip.show();
}
}
else{
calAlert_Status = false;
Particle.publish("MeetingStarted-FadingtoWhite"); ////publishing meeting notification in cloud
}
}
else{
//Back to cool white
now = millis();
if (((now - lastUpdate) >= 900000) && ((now - lastUpdate) <= 1800000)){
cRed = map((now - lastUpdate), 900000, 1800000, 0, 230);
cGreen = map((now - lastUpdate), 900000, 1800000, 0, 25);
cBlue = map((now - lastUpdate), 900000, 1800000, 0, 25);
if (cRed > 25){
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, (255-cRed), cGreen, cBlue);
}
strip.show();
}
}
}
}
//Function to get calendar alert from IFTTT through cloud
int setCalAlert(String command){
if(command == "True") {
calAlert_Status = true;
lastUpdate = millis();
Particle.publish("CalenderAlert-FadingtoRed"); //publishing alert received on cloud
return 1;
}
return -1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .