Skills Dev III: Ambient Calendar Alert

Made by Weiqing Wang

This practice exercise is to create an ambient calendar alert using a neopixel strip. The ambient orb will send an alert to your device a few minutes before an appointment. The neopixels are programmed to respond by fading up slowly and signalling there’s an event and changing color as the event approaches. Ultimately it will then fade out after the event has begun.

Created: November 30th, 2022

0

Outcome

The neopixel is connected with my Google calender with IFTTT. 15 minutes before a meeting on your calendar, IFTTT will call the function. Over the 15 minutes between the Particle function being called, and the start of the meeting, program your Neopixel to slowly fade to red. For 15 minutes after your meeting was due to start have it slowly fade back to white. 

Demo see video below. It is a short demo where the functions happened in 1 minutes. 


0

Process

  1. Program my Neopixel Ring to display a cool white by default.
  2. Add a Particle Cloud function and use it to change the color to red immediately. Test this with the Particle Console. 
  3. Program my Neopixel to fade to red over 1 minute using millis()
  4. After the initial transition, now program my Neopixel to fade from red back to white over 1 minute using millis()
  5. With those working as quick transitions, test it working over 15 minutes
  6. Hook it up to IFTTT.

I finished the code with the help of TA. He helped me debugged the indentation of the code, which affects the action sequences. 

0

Reflection

My IFTTT connection shows the function call is failed but the neopixel can fade to red and return to white when the event triggers. I should try to debug this if I have more time. 

Debugging with TA also help me cultivate the habbit of writing code with clear indentation to avoid mistakes when there are many loops or if statements.

0
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include "neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

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

int r = 255;    // set rgb value to make changing color more convenient
int g = 255;
int b = 255;
int remindBefore = 5;                          // set notification trigger time (how many minutes before the meeting)
int fadeInPeriod = remindBefore * 60 * 1000;
int fadeOutPeriod = remindBefore * 60 * 1000;
unsigned long lastFade = 0;     //set timer
unsigned long now = millis();
bool fadeIn = FALSE;
bool fadeOut = FALSE;

void setup() {
    strip.begin();
    // start with white 
    uint32_t c = strip.Color(255,255,255); // Pure white
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
        }
    strip.show();
    // remind function
    Particle.function("alert", turnRed);
}

int turnRed(String command)
{
    fadeIn = TRUE;
    return 1;

}

void loop() {
    if (fadeIn == TRUE){
    while (g > 0 && b > 0){
        if ((now - lastFade) >= fadeInPeriod / 255){   // the g/b value will decrease gradually to 0 over fadeInPeriod
            g--;
            b--;
            lastFade = now;
        }
        uint32_t c = strip.Color(r,g,b);     // update the neopixels after finishing the change of rgb value 
        for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
        strip.show();
       }
        now = millis();  // now gets updated after each g&b update
    }
    fadeIn = FALSE;
    fadeOut = TRUE;
}

    if (fadeOut == TRUE){
        lastFade = 0;
        while (g < 255 && b < 255){
            if ((now - lastFade) >= fadeOutPeriod / 255){   // the g/b value will decrease gradually to 0 over fadeInPeriod
               g++;
               b++;
               lastFade = now;
           }
        uint32_t c = strip.Color(r,g,b);     // update the neopixels after finishing the change of rgb value 
        for( int i = 0; i < strip.numPixels(); i++ ){
            strip.setPixelColor(i, c); // set a color 
            strip.show();
        }
        now = millis(); 
        }
    }


}
Click to Expand
0
48675 - Design for IoT - Skill Exercise 3 - Ambient Calendar Alert
Weiqing Wang - https://youtube.com/shorts/BsPrCNzwYz4?feature=share
x
Share this Project

Courses

About

This practice exercise is to create an ambient calendar alert using a neopixel strip. The ambient orb will send an alert to your device a few minutes before an appointment. The neopixels are programmed to respond by fading up slowly and signalling there’s an event and changing color as the event approaches. Ultimately it will then fade out after the event has begun.