Skills Dev III: Ambient Orb

Made by Shih-Hsueh Wang

Created: November 16th, 2022

0

Outcome

    • Ambient orb: The Neopixel will be triggered and light up in white 15 minutes before the event on Google Calendar starts. It will gradually turn red and blink when there is only 1 minute left. Video

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

#define PIXEL_PIN A5
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

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

int durationOfFade = 1000 * 60 * 0.5;
long timeStartedAt = 0;
bool timeStarter = false;



void setup() {
    
    strip.begin();
    strip.show();
    Particle.function("fadeUp", HandleFadeUp);
    
    Serial.begin (9600);
}

void loop() {

    if (timeStarter == true){
        
        long timeNow = millis();
        long timeElapsed = timeNow - timeStartedAt;
        int r = 255;
        int g = 255;
        int b = 255;
        
        if (timeElapsed < durationOfFade){
            int colorValue = map(timeElapsed, 0, durationOfFade, 0, 255);
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, r, g - colorValue, b - colorValue);
            }
            strip.show();
            delay (10);
        }else if ( (durationOfFade - timeElapsed) < 1000*10){

            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 255, 0, 0);
            }
            strip.show();
            delay (100);   
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 0, 0, 0);
            }
            strip.show();
            delay (100);     
        }
      
    }
    
}

int HandleFadeUp (String cmd){
    

    timeStartedAt = millis();
    timeStarter = true;   
    
    return 1;
    
    if (cmd == "off"){
        timeStarter = false;
        for (int i = 0; i < strip.numPixels(); i++){
            strip.setPixelColor (i, 0, 0, 0);
            }
        strip.show();
        return -1;    
    }

}
Click to Expand
0

Process

I was trying to make the Neopixel off once the countdown for the event completes. In order to do that, I set else if ( ((durationOfFade - timeElapsed) > 0) && ((durationOfFade - timeElapsed) < 1000*10)) to indicate when to blink and when to stop from blinking so I can turn the Neopixel off by adding the next line of code. Yet, the code didn't function well and I couldn't stop it from blinking. 

0
void loop() {

    if (timeStarter == true){
        
        long timeNow = millis();
        long timeElapsed = timeNow - timeStartedAt;
        int r = 255;
        int g = 255;
        int b = 255;
        
        if (timeElapsed < durationOfFade){
            int colorValue = map(timeElapsed, 0, durationOfFade, 0, 255);
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, r, g - colorValue, b - colorValue);
            }
            strip.show();
            delay (10);
        }else if ( ((durationOfFade - timeElapsed) > 0) && ((durationOfFade - timeElapsed) < 1000*10)){

            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 255, 0, 0);
            }
            strip.show();
            delay (100);   
            
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 0, 0, 0);
            }
            strip.show();
            delay (100);     
        
        } else {
            for (int i = 0; i < strip.numPixels(); i++){
                strip.setPixelColor (i, 0, 0, 0);
            }
            strip.show();
            delay (100);                     
        }
        
        Serial.println ((durationOfFade - timeElapsed));
        delay(1000);
    }
    
    
}
Click to Expand
0

Reflection


x