Skills Dev III: Ambient Orb

Made by Sohail Shaikh

This practice exercise will challenge you to create an ambient calendar alert using a neopixel strip. By the end of the project, you’ll have connected your Particle device to your Google Calendar through IFTTT and display an alert using a Neopixel LED array

Created: December 15th, 2022

0

Outcome

    • In this project, I used a Neopixel strip and a push button to create an ambient calendar alert.
    • Once the circuit and functionality were set up, the particle device was connected to the Google Calendar through IFTTT. This enabled Neopixel to show an alert 15 mins before the meeting start time.
    • 15 minutes before the meeting start time, The Neopixel will light up and will fade to blue for initial 5 minutes. 
    • For the last 10 minutes before the meeting start time, The Neopixel will start transitioning from blue to Red indicating an alert about the meeting. 
    • Once the meeting is initiated, in the last 5 minutes the neopixel will fade out to white color and eventually switch off till another meeting starts. 
    • There is a Particle.function to allow us to customize the time of the countdown for the Neopixel strip to light up. Once the user enters input in minutes, it is converted to milliseconds and the entire time frame is divided into three parts- initial 25%, middle 50%, and 25% post-meeting is completed. 
    • Also, there is a pushbutton that allows the user to dismiss the alert if it is being pressed for 3 seconds or more.
    • For the demo purposes. I have increased the speed of the Fadeup of Neopixel strip in the video given below. 

0

Process

  •  I started this project by soldering the neopixel and developing a basic circuit to understand the functionality of neopixel strip such as switching on the LED's and learning on how to fade the neopixel over time.
  • I then learnt on how to fade Neopixels using the millis(). Using millis() was a tricky part for me initially. 
  • Once I designed the functionality and circuit was completed. I then extended my functionality to incorporate a push button to allow user to dismiss the alert. 
  • Post completion of the functionality, I tried connecting the circuit to the IFTTT platform. It was pretty easy to connect the circuit to the IFTTT platform following the steps given in the lab website. 
  • One of the challenge was to debug, whether the calendar alert is getting pushed or not. as the trigger time was not exactly at 15 mins prior to meeting start time. 
0

Reflection

  • In this project, I learnt on how I could connect the circuit to the IFTTT platform on cloud and trigger alerts or notifications using the applets present on the IFTTT platform. I also learnt using the neopixel strip which was different than a normal LED. 
  • I also learnt to develop different functionalities by breaking each into smaller parts.

0
#include <neopixel.h>

#define PIXEL_PIN D3
#define PIXEL_COUNT 8 //for stick, 16 for ring
#define PIXEL_TYPE WS2812B //for 4pin neopixels, WS2812/WS2813 for 6pin

Adafruit_NeoPixel strip = Adafruit_NeoPixel( PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int buttonPin = D2;
bool calAlert = false;
unsigned long meetingstartTime= 0;
unsigned long totalFadeInTime = 120000;   //1200000
unsigned long initialFadeInTime = 30000;  //300000
unsigned long middleFadeInTime = 60000;    //600000
unsigned long FadeOutTime = 30000;    //300000

unsigned long timeSinceCalAlert= 0;
int initialFadeIn = 0;
int middleFadeIn = 0;
int finalFadeOut = 0;

// Function to take fadein time as input from user 
int userfadeInTime(String command)
{ 
    int input = 0;
    input = command.toInt();
        if(input > 0) 
        {
            //calAlert = true;
            
            // Divide the user fadeintime into initial, middle and final fade out time by 25%, 50% and 25% respectively.
            totalFadeInTime = input * 60 * 1000;
            initialFadeInTime= 0.25 * totalFadeInTime;
            middleFadeInTime= 0.5 * totalFadeInTime;
            FadeOutTime = 0.25 * totalFadeInTime;
            return 1;
        }
        else
        {
            return 0;
        }
}
 
 

// this function automatically gets called upon getting a POST request
int googleCalAlert(String command)
{
    Serial.println("Calendar Alert Status in cloud function:");
        Serial.println(calAlert);

    meetingstartTime = millis(); 
    if(command == "1"){
        calAlert = !calAlert;
        Serial.println(calAlert);
        meetingstartTime = millis(); 
        Serial.println(meetingstartTime);
    }
    if(calAlert == true){
        return 1;
    }
    return 0;
}


void setup() {
    
    pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
    strip.begin();
    strip.show();
    Serial.begin( 9600 );         // Setups Serial Communications
    //Cloud Functions
    Particle.function("Google_Calendar_Alert", googleCalAlert);
    Particle.function("Please input the fade-in time in mins", userfadeInTime);
    
    Particle.variable("Time since the meeting alert received in mins", timeSinceCalAlert);
}

int buttonpressStartTime =0;
int buttonpressTotalTime =0;
bool buttonPressed =false;


void loop() {
    
    int buttonState = digitalRead( buttonPin );
    if( buttonState == LOW )
    {
        Serial.println("buttonpress status");
        Serial.println(buttonState);
        buttonPressed =true;
        Serial.println("buttonpressed  or not ");
        Serial.println(buttonPressed);
        buttonpressStartTime = millis();
  }
  
    if(buttonState == HIGH & buttonPressed == true){
        buttonpressTotalTime = millis()- buttonpressStartTime;
        Serial.println(buttonState);
        Serial.println(buttonpressTotalTime);
        if(buttonpressTotalTime>= 3000)
        {
        calAlert = false;
            for(int i=0; i<strip.numPixels(); i++)
            {
                strip.setPixelColor(i, 0, 0 , 0);
            }
            strip.show();
    buttonPressed = false;        
    }
    }

    timeSinceCalAlert= millis()- meetingstartTime;
    
    if(calAlert == true & initialFadeIn <= 255)
    { // rgb 0 0 255 for blue
        int initialDifference=0;
        initialDifference = millis()-meetingstartTime;
        initialFadeIn = map(initialDifference, 0, initialFadeInTime, 0, 255);
        Serial.println(" In initial fade in Status");
        Serial.println("Initial FadeInValue");
        Serial.println(initialFadeIn);
        for(int i=0; i<strip.numPixels(); i++)
            {
                strip.setPixelColor(i, 255- initialFadeIn, 255- initialFadeIn, 255);
            }
        strip.show();
    }
    
    else if(calAlert == true & middleFadeIn <= 255 & initialFadeIn >= 255)
    { // rgb 255 0 0 for red
        int middleDifference=0;
        middleDifference = millis()- (meetingstartTime+ initialFadeInTime);
        middleFadeIn = map(middleDifference, 0, middleFadeInTime, 0, 255);
        Serial.println(" In middle millis value is");
        int a = millis();
        //Serial.println(meetingTrigger);
        Serial.println(a);
        Serial.println(" In middle fade in Status");
        //Serial.println(meetingTrigger);
        Serial.println("middle FadeInValue");
        Serial.println(middleFadeIn);
        for(int i=0; i<strip.numPixels(); i++)
            {
                strip.setPixelColor(i, middleFadeIn , 0 , 255- middleFadeIn);
            }
        strip.show();
    } 
    else if(calAlert == true & finalFadeOut <= 255  & middleFadeIn >= 255 & initialFadeIn >= 255)
    { // rgb 255 255 255 for white
        int finalDifference=0;
        finalDifference = millis()- (meetingstartTime + middleFadeInTime + initialFadeInTime) ;
        finalFadeOut = map(finalDifference, 0, FadeOutTime, 0, 255);
        Serial.println(" In Final fade in Status");
        Serial.println("Final FadeInValue");
        Serial.println(finalFadeOut);
        for(int i=0; i<strip.numPixels(); i++)
            {
                strip.setPixelColor(i, 255, finalFadeOut, finalFadeOut);
            }
        strip.show();
    } 
    
    if(finalFadeOut >= 255){
        calAlert = false;
        initialFadeIn = 0;
        middleFadeIn = 0;
        finalFadeOut = 0;
        for(int i=0; i<strip.numPixels(); i++)
            {
                strip.setPixelColor(i, 0, 0 , 0);
            }
            strip.show();
    }
    strip.show();
  //  delay(400);
    }
Click to Expand
0
Wire up a pushbutton and allow the pushbutton to dismiss the alert if pressed for 3 seconds.
Sohail Shaikh - https://youtube.com/shorts/x9gYW_jT8gI?feature=share
0
A full fledged ambient Orb
Sohail Shaikh - https://youtu.be/7ew1gZ1LMsE
x
Share this Project

Courses

About

This practice exercise will challenge you to create an ambient calendar alert using a neopixel strip. By the end of the project, you’ll have connected your Particle device to your Google Calendar through IFTTT and display an alert using a Neopixel LED array