Ambient Notification
Made by Adwoa Asare
Made by Adwoa Asare
When a notification function is called, a pattern displays on the LED strip. A button is used to deactivate the notification.
Created: November 13th, 2024
The goal of this project was to make an ambient calendar notification system that would alert you when there is an event on your Google Calendar in 15 minutes. The ambient alert would be a colorful pattern displayed on an LED switch. When the user sees the notification, they can dismiss it by holding a button for 3 seconds.
I made a simple circuit using the Adafruit addressable LED strip, a button, and a Particle Photon 2 microcontroller. I tried for a long time to integrate it with Webhooks and IFTTT so that I could call a Particle function based on my Google Calendar. I ran into a lot of issues with this method. Even after I set it up, I could not implement it since Webhooks is no longer available for free. I changed my approach and made my function just callable from the Particle Console instead.
I used the millis() function and a Boolean flag to determine if the button had been held for 3 seconds. This took a while to troubleshoot because one of the wires I had plugged into my button was broken and I did not realize. Once I switched out wires everything worked fine.
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// Include Particle Device OS APIs
#include "Particle.h"
// VARIABLES
#define PIXEL_PIN SPI // plug into pin MO
#define PIXEL_COUNT 7 // 0 addressed
//#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE WS2812B
int buttonPin = D3;
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
unsigned long buttonPress = 0;
unsigned long now;
bool buttonHold = FALSE;
int buttonState;
uint32_t w = strip.Color(0, 0, 0, 255); // Pure white
uint32_t c1 = strip.Color(0, 0, 255); // Blue
uint32_t c2 = strip.Color(0, 255, 0); // Green
// setup() runs once, when the device is first turned on
void setup() {
Particle.function("notify",led_notification);
strip.begin();
pinMode( buttonPin , INPUT_PULLUP);
Particle.variable("button", buttonState);
Particle.variable("hold", buttonHold);
Particle.variable("now", now);
Particle.variable("now", buttonPress);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
now = millis();
buttonState = digitalRead( buttonPin );
//Check how long button is pressed
if (buttonState == LOW && buttonHold == FALSE){
buttonHold = TRUE;
buttonPress = now;
}else if (buttonState == LOW && buttonHold == TRUE){
if((now - buttonPress) >= 3000){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i,w); // set a color
strip.show();
}
}
}else{
buttonHold = FALSE;
}
}
//function do display to LED strip when there is a notification
int led_notification(String command){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c1); // set a color
strip.show();
delay( 100 );
}
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 100 );
}
return 1;
}
Click to Expand
When a notification function is called, a pattern displays on the LED strip. A button is used to deactivate the notification.