An Ambient Orb

Made by Xuan Peng ·

An ambient orb reminds users of the upcoming events by connecting to Google Calender.

Created: December 7th, 2023

0

Process

I came across several coding problems when trying to understand how millis() works. Therefore I divided my code into sereval parts to test it separately to find out what the errors were. With the help of my roommate from school of computer science and Max Wu, I manged to run the code eventually.

0
//SkillDev3

// 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 16
#define PIXEL_TYPE WS2812

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

//two different color settings
uint32_t w = strip.Color(255, 255, 255);
uint32_t r = strip.Color(255, 0, 0);
uint16_t i;

//brightness and timing variables
int brightness = 0;
unsigned long lastFade = 0;

// timing settings for different states
int fadeDuration = 10000;       // Time to fade between colors
int transitionDuration = 20000; // Time for transitioning between events
int outDuration = 10000;        // Time to keep the lights on before turning off

long timeStart = -1;
bool timerStarted = false;
// Added flag to track the direction of the fade
bool fadingToRed = true;


void setup() {
    
    strip.begin();

    // Set the initial state to white
    for (int i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, w);
    }

    strip.show();
    
    // Add the IFTTT Function
    Particle.function("CalEvent", calEvent); 
}


void loop() {
    // Check if the timer is started
    if (timerStarted) {
        long timeNow = millis();
        long timeElapsed = timeNow - timeStart;

        if (timeElapsed < fadeDuration) {
            // Calculate color value for fading effect
            int colorValue = map(timeElapsed, 0, fadeDuration, 0, 255);

            // Update RGB values based on fading direction
            int r, g, b;
            if (fadingToRed) {
                r = 255;
                g = 255 - colorValue;
                b = 255 - colorValue;
            } else {
                r = 255;
                g = 0 + colorValue;
                b = 0 + colorValue;
            }

            // Set NeoPixel colors
            for (int i = 0; i < strip.numPixels(); i++) {
                strip.setPixelColor(i, r, g, b);
            }
            strip.show();
        } else {
            if (fadingToRed) {
                // Toggle the direction of the fade
                fadingToRed = !fadingToRed;

                // Reset the timer and flag
                timeStart = millis();
            } else {
                // Set the light bar to white and stop the timer
                for (int i = 0; i < strip.numPixels(); i++) {
                    strip.setPixelColor(i, 255, 255, 255);
                }
                strip.show();
                timerStarted = false;

                // Reset the fading direction for the next event
                fadingToRed = true;
            }
        }
    }
}

int calEvent(String cmd) {
    timeStart = millis();
    timerStarted = true;
    return 1;
}
Click to Expand
0
Skill Dev 3
Xuan - DIoT - https://youtu.be/RcupbMS_G5Y
0

Reflection

I really like the IFTTT feature because it solves some problems that I would really encounter in my daily life.

However, I have found that this feature does not run very consistently and may have a time delay, I don't know if this is due to a problem with my code writing or if the network is causing the delay, it may need to be explored further.

x
Share this Project

This project is only accessible by signed in users. Be considerate and think twice before sharing.


Courses

48-675 Designing for the Internet of Things

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

An ambient orb reminds users of the upcoming events by connecting to Google Calender.