SkillDev3 - Rahul Jha

Made by Rahul Jha

Creating an Ambient Calendar Alert device

Created: November 28th, 2021

0

Outcome

    • Build understanding of ambience through hands-on exploration
    • Build familiarity with adding libraries and extending functionality in  project
    • Build familiarity with for loops and conditional logic
    • Bain understanding of how to program advanced outputs - Neopixel LED array
    • Finally, create an ambient calendar alert using a neopixel strip - connect Particle device to Google Calendar through IFTTT and display an alert using a Neopixel LED array
0

Process

  • To carry out the final goal, performed the 4 practice examples to familiarize with the above-mentioned concepts.

    Exercise 1: light-up pixel by pixel then reverse the sequence turning each pixel off one by one.


0
// 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
0
SkillDev3-Ex1
rahuljha89 - https://youtu.be/h9zRudX1TGU
0

Exercise 2: Modify the code to light up blue, then red, then green then white in sequence.

0
// 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
0
SkillDev3-Ex2
rahuljha89 - https://youtu.be/GxhAFCTd0-Q
0

Exercise 3: Change the code to only light up only one pixel at a time. With each loop move that pixel one position higher. When it reaches the final pixel, restart the sequence at zero i.e. build a single pixel that will continually cycle.

0
// 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
0
SkillDev3-Ex3
rahuljha89 - https://youtu.be/bpEv1cGhrkI
0

Exercise 4: Add three Particle.function to set the Red, Green and Blue components. Allow these values to be set from 0-255 and as they are set to change all of the pixels on the LED strip to that color.

0
// 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
0
SkillDev3-Ex4
rahuljha89 - https://youtu.be/Gx6pcoADTU4
0

Ambient Calendar Alert Device:

  • Programed the Neopixel Ring to display a cool white by default.

  • Added a Particle Cloud function and used it to connect particle cloud to IFTTT applet.
  • Configured IFTTT to trigger an event based on google calender alert notification and send it to particle cloud function with 'True' command.
  • When the 'True' command is received the particle cloud function, enables the if condition after which the Neopixel starts fading to RED gently over the next 15 minutes. Also, published an event on the cloud "to update the start receiving of calendar alert trigger from IFTTT.
  • Once the meeting start time reaches, the Neopixel starts fading back to default cool WHITE over the next 15 minutes. Again an event is published on the cloud to represent the start of this process.

0
// 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
0
SkillDev3-AmbCalAlert
rahuljha89 - https://youtu.be/kXzJ9_AvjhI
0

Below pics show the sequence of important events of the Ambient Calendar Event Device:

0

Reflection

  • It was a nice experience to develop the ambient product through hands-on exploration. 
  • Learned about implementing IFTTT and particle cloud functionality apart from Neopixel programming and libraries.
  • I had faced quite a few challenges while developing this project which made me learn a lot. IFTTT implementation, 'Particle.function argument reading to name a few. 
  • Another important implementation that took time was the millis(). Since it returns the time from the start of the program, I had to call it in the particle cloud function. This made it possible to run this implementation with every trigger event from IFTTT. Earlier it was working only for the first time. 
  • One thing which is a little weird till now is that there is a delay between the google calendar and the IFTTT application. The applet runs either 1-2 minutes earlier or later than the actual calendar alert. I am not sure if the issue is with my internet connection or the IFTTT app, I am still monitoring it to confirm.
     

x
Share this Project

Courses

About

Creating an Ambient Calendar Alert device