// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
//Set pixel COUNT, PIN, and TYPE
#define PIXEL_COUNT 16
#define PIXEL_PIN D5
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int red = 25; //to track the value of Red color
int green = 25; //to track the value of Green color
int blue = 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, red, green, blue);
}
strip.show();
}
void loop() {
if (calAlert_Status == true){
//Fade to red
now = millis();
if ((now - lastUpdate) <= 900000){
red = map((now - lastUpdate), 0, 900000, 20, 255);
green = map((now - lastUpdate), 0, 900000, 0, 25);
blue = map((now - lastUpdate), 0, 900000, 0, 25);
if(green<0){
green = 0;
blue = 0;
}
if (red <= 255) {
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, red, (25-green), (25-blue));
}
strip.show();
}
}
else{
//Reinitiailizing the calender alert variable after the meeting time reached
calAlert_Status = false;
Particle.publish("MeetingStarted-FadingtoWhite"); ////publishing meeting started notification on cloud
}
}
else{
//Back to cool white
now = millis();
if (((now - lastUpdate) >= 900000) && ((now - lastUpdate) <= 1800000)){
red = map((now - lastUpdate), 900000, 1800000, 0, 230);
green = map((now - lastUpdate), 900000, 1800000, 0, 25);
blue = map((now - lastUpdate), 900000, 1800000, 0, 25);
if (red > 25){
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, (255-red), green, blue);
}
strip.show();
}
}
}
}
//Function to get calender alert from IFTTT throgh cloud
int setCalAlert(String command){
if(command == "True") {
calAlert_Status = true;
lastUpdate = millis();
Particle.publish("CalenderAlert-FadingtoRed"); //publishing alert recieved notification 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. .