SkillDev3 - Rahul Jha
Made by Rahul Jha
Made by Rahul Jha
Creating an Ambient Calendar Alert device
Created: November 28th, 2021
// 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);
void setup() {
strip.begin();
strip.show(); //Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
//Switch on each pixel in blue one by one
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, 0, 0, 10);
strip.show();
delay(1000);
}
delay(100);
//Switch off each pixel one by one
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, 0, 0, 0);
strip.show();
delay(1000);
}
}
Click to Expand
// 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);
void setup() {
strip.begin();
strip.show(); //Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t b = strip.Color(0, 0, 255);
uint32_t r = strip.Color(255, 0, 0);
uint32_t g = strip.Color(0, 255, 0);
uint32_t w = strip.Color(255, 255, 255);
//Switch on each pixel in blue all at once
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, b);
}
strip.show();
delay(1000);
//Switch on each pixel in red all at once
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, r);
}
strip.show();
delay(1000);
//Switch on each pixel in green all at once
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, g);
}
strip.show();
delay(1000);
//Switch on each pixel in white all at once
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, w);
}
strip.show();
delay(1000);
}
Click to Expand
// 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);
void setup() {
strip.begin();
strip.show(); //Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t w = strip.Color(255, 255, 255);
//Switch on each pixel in blue all at once
for(i=0; i<strip.numPixels(); i++){
if(i>0){
strip.setPixelColor( (i-1), 0, 0, 0);
}
strip.setPixelColor( i, w);
strip.show();
delay(1000);
}
strip.setPixelColor( 15, 0, 0, 0);
strip.show();
//delay(1000);
}
Click to Expand
// 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);
//Set variables for colors to store values values from cloud
int red = 0;
int green = 0;
int blue = 0;
void setup() {
strip.begin();
strip.show(); //Initialize all pixels to 'off'
//Particle function on cloud
Particle.function("Red", getRedColor);
Particle.function("Green", getGrreenColor);
Particle.function("Blue",getBlueColor);
}
void loop() {
uint16_t i;
//Switch on each pixel all at once
for(i=0; i<strip.numPixels(); i++){
strip.setPixelColor( i, red, green, blue);
strip.show();
}
delay(100);
}
//Function to get command or value for red color from cloud
int getRedColor(String command){
int value = atoi(command);
if(value >= 0 && value <= 255){
red = value;
return 1;
}
return -1;
}
//Function to get command or value for green color from cloud
int getGrreenColor(String command){
int value = atoi(command);
if(value >= 0 && value <= 255){
green = value;
return 1;
}
return -1;
}
////Function to get command or value for blue color from cloud
int getBlueColor(String command){
int value = atoi(command);
if(value >= 0 && value <= 255){
blue = value;
return 1;
}
return -1;
}
Click to Expand
// 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