Skills Dev III: Ambient Orb

Made by Nick Possi-Moses · UNLISTED (SHOWN IN POOLS)

An ambient orb, a light that sits passively in the background and is integrated seamlessly with one's environment, will be powered on to display white light. When there is a meeting about to start, the orb will gradually turn more and more red. As the meeting starts, the orb will gradually turn less and less red until it returns to normal state (i.e. white).

Created: December 14th, 2022

0

Outcome

    • The outcome of this project was to create an ambient orb (a light that sits passively in the background and is seamlessly integrated with one's environment). The orb would display real time information by being hooked up to a cloud function. In this case, it was hooked up to my Google Calendar so that when a meeting was about to start, the light would alert me that a meeting was about to start and that the meeting was underway (the way this was communicated was via a gradually more and more intense red color being emitted from the orb, and a gradually less and less intense red color being emitted from the orb until it returned to its normal 'on' state, which is white). 

0

Process

I tried at least ten different ways to code this...I won't include the 'bad code' for readability purposes, but some of the things I tried include:

-Using a variable to trigger an event if less than x minutes had passed and an event if more than x minutes had passed. The light would gradually become more or less intense depending on each event's conditions.

-Using void functions to kick off the next series of actions expected

-Creating one big nested if function

-Many more approaches which all did not work

After struggling to understand why my attempts were not working, I realized I needed to spend time learning how to properly debug the code. I then spent A LOT of time learning how to use Serial.print and the command prompt to trace where the code was working and where it was not. After some time fine-tuning the code, I was able to come up with a way to 'mostly' get the program to work. Admittedly, this code could be optimized, but it's a LONG WAY from where I started.

0

Reflection

I learned a few things. First, I learned how to debug code using the serial function. Frankly, had I not invested time in this, I don't think I would have been able to figure out how to get the program to work. I also enhanced my learning of how circuit boards work. I felt more confident wiring the neopixel and the switch this time around; whereas, on the last lab, I felt pretty shaky on wiring. I felt more confident tying prior labs to this lab, as is demonstrated by the switch that is configured on the breadboard. I learned, too, how to use webhooks via IFTTT. Though the instructional video was very helpful on the class website, I could not figure out how to actually get my webhook to communicate to my program (I kept getting a 400 error). I realized that I needed to pass a value back from webhook that my program could consume. So, I ended up entering a response item that could be used by my program. A very valuable lesson for me. Additionally, I learned enhanced my understanding of how functions work. Initially, my program only included one additional function (aside from setup and void). Once I experimented a bit, I realized that I would need to include another function to transition from a pre-meeting state to a post-meeting state.

Lastly, I learned to ask for help. I didn't ask for much help with this lab and it was very frustrating - I feel now that if I had asked for help earlier I could have easily avoided some of the silly mistakes I had made.

0
// This #include statement was automatically added by the Particle IDE.

#include <neopixel.h>

//Set pixel COUNT, PIN, and TYPE

#define PIXEL_COUNT 8

#define PIXEL_PIN D2

#define PIXEL_TYPE WS2812

// Setup Pixel

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

// Define switch

int switchPin = D3;

int switchState = LOW;

// Define duration of fade variable to 15 minutes (1000 = 1 second, 60 seconds = 1 min, 15 min)

int durationOfFade = 1000 * 60 * .25;

// Define variable to hold the start time

long timeStartedAt = -1;

long resetTimeStartedAt = -1;

// Define variable to hold value for whether timer has started or not (IFTTT Function)

bool timerStarted = FALSE;

bool resetTimerStarted = FALSE;

void setup() {

// Sets pin as input

pinMode( switchPin , INPUT_PULLUP);

// Set pixel to off state

strip.begin();

strip.show();

//Set up IFTTT Calendar Function

Particle.function("eventAlert", handleCalendarAlert);

Serial.println("Setup Complete");

}

void loop() {

int switchState = digitalRead( switchPin );

//Define whether Pixel should be on or off

if (switchState == LOW) {

if (timerStarted == TRUE) { //Determine whether timer has started or not

long timeNow = millis(); //Get the time now

long timeElapsed = timeNow - timeStartedAt; //Define how much time has elapsed

Serial.print(timeElapsed);

if (timeElapsed < durationOfFade) {

int colorValue = map(timeElapsed, 0, durationOfFade, 0, 255); //Controls color fade. Starting point is 0 to max durationOfFade value, which is then mapped to 0-255

Serial.print("Color Value: ");

Serial.print(colorValue);

int r = colorValue;

int g = 0;

int b = 0;

for( int i = 0; i <strip.numPixels(); i++) {

strip.setPixelColor( i, r, g, b);

}

strip.show();

}

else {

timerStarted = FALSE; //reset timer

resetHandler(1);

Particle.publish("timerFinished");

Serial.println("timerFinished ");

}

}

else if (resetTimerStarted == TRUE) {

Serial.print("\t");

Serial.println("Reset Timer Running");

long timeNow = millis();

long timeElapsed = timeNow - resetTimeStartedAt;

if (timeElapsed < durationOfFade) {

int colorValue = map(-timeElapsed, 0, durationOfFade, 0, 255); //Controls color fade. Starting point is 0 to max durationOfFade value, which is then mapped to 0-255

Serial.print("Color Value: ");

Serial.print(colorValue);

int r = colorValue;

int g = 0;

int b = 0;

for( int i = 0; i <strip.numPixels(); i++) {

strip.setPixelColor( i, 255, 255-colorValue, 255-colorValue);

}

strip.show();

}

else {

resetTimerStarted = FALSE; //reset timer

Particle.publish("timerFinished");

Serial.println("Reset Timer Finished ");

}

}

else {

delay(1000);

powerOn();

}

}

//TURN LIGHTS OFF BECAUSE SWITCH IS OFF

else {

for (int i = 0; i < strip.numPixels(); i++) {

strip.setPixelColor (i, 0, 0, 0);

}

strip.show();

}

}

// Define IFTTT Calendar Function Value

int handleCalendarAlert ( String cmd) {

if(cmd == "TRUE") {

timeStartedAt = millis();

timerStarted = TRUE;

return 1;

}

return -1;

}

int resetHandler (int value) {

if (value == 1) {

resetTimeStartedAt = millis();

resetTimerStarted = TRUE;

Particle.publish("resetTimerTriggered");

Serial.println("resetTimerTriggered");

return 1;

}

return -1;

}

void powerOn () {

for (int i = 0; i < strip.numPixels(); i++) {

strip.setPixelColor(i, 255, 255, 255);

strip.show();

}

}
Click to Expand
0
IoT_Lab3
Nicholas Possi-Moses - https://www.youtube.com/watch?v=0npW_VzQlUI
x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

An ambient orb, a light that sits passively in the background and is integrated seamlessly with one's environment, will be powered on to display white light. When there is a meeting about to start, the orb will gradually turn more and more red. As the meeting starts, the orb will gradually turn less and less red until it returns to normal state (i.e. white).