Shivani Kannan - Ambient Orb

Made by Shivani Kannan

Create an ambient calendar alert using a neo pixel strip.

Created: November 13th, 2024

0

Intention

To create an ambient calendar alert using a neo pixel strip.

0

Process

Components: Neopixel Strip, Wires, Photon 2, Breadboard USB cable
1. Soldering: Soldering the 3 wires to the neo pixel
2. Creating the circuit: took the help of the circuit diagram on the website to connect the different components
3. Trial: Loop code for neo pixel (without particle cloud function) to test if it is working 
4. Adding a particle cloud function to code & learning more about it.
5. Programing neo pixel to display cool white by default.
6. Chatgpt to debug code
7. On calling function, fade from white to red
8. Chatgpt to debug code
9. On calling function, fade from white to red and then back to white

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

// Include Particle Device OS APIs
#include "Particle.h"
#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

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

SerialLogHandler logHandler(LOG_LEVEL_INFO);

bool fadeToRed = false;          // Flag to start the fade
bool fadeToWhite = false;        // Flag to fade back to white
unsigned long fadeStartTime = 0; // Time when the fade starts
const unsigned long fadeDuration = 30000; // 30 seconds in milliseconds

// Function to set initial cool white color
void displayCoolWhite() {
    for (int i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, 200, 200, 255); // Cool white RGB values
    }
    strip.show();
}

// Particle Cloud function to start fading to red
int startFadeToRed(String command) {
    fadeToRed = true;              // Set flag to start fading to red
    fadeToWhite = false;           // Ensure the fade back to white is off
    fadeStartTime = millis();      // Record start time of fade
    return 1;
}

    void setup() {
        strip.begin();
        displayCoolWhite();              // Display cool white on startup
        Particle.function("fadeToRed", startFadeToRed); // Register Particle Cloud function
}

void loop() {
    if (fadeToRed) {
        // Calculate elapsed time since fade started
        unsigned long elapsed = millis() - fadeStartTime;

        if (elapsed >= fadeDuration) {
            // Fade to red is complete, set color to solid red and start fading back to white
            for (int i = 0; i < strip.numPixels(); i++) {
                strip.setPixelColor(i, 255, 0, 0); // Solid red color
            }
            strip.show();
            fadeToRed = false;          // Stop fading to red
            fadeToWhite = true;         // Start fading back to white
            fadeStartTime = millis();   // Reset fade start time for the next fade
        } else {
            // Calculate intermediate color values based on elapsed time
            float progress = (float)elapsed / fadeDuration;
            int redValue = (int)(200 + progress * (255 - 200));
            int greenValue = (int)(200 - progress * 200);
            int blueValue = (int)(255 - progress * 255);

            for (int i = 0; i < strip.numPixels(); i++) {
                strip.setPixelColor(i, redValue, greenValue, blueValue);
            }
            strip.show();
        }
    } else if (fadeToWhite) {
        // Calculate elapsed time since fade back to white started
        unsigned long elapsed = millis() - fadeStartTime;

        if (elapsed >= fadeDuration) {
            // Fade back to white is complete, set color to solid cool white
            displayCoolWhite();
            fadeToWhite = false; // Stop fading
        } else {
            // Calculate intermediate color values for fade back to white
            float progress = (float)elapsed / fadeDuration;
            int redValue = (int)(255 - progress * (255 - 200));
            int greenValue = (int)(0 + progress * 200);
            int blueValue = (int)(0 + progress * 255);

            for (int i = 0; i < strip.numPixels(); i++) {
                strip.setPixelColor(i, redValue, greenValue, blueValue);
            }
            strip.show();
        }
    }
}
Click to Expand
0

Outcome

The neo pixel is white by default. When the function is called (on the particle console or app) the neo pixel fades from white to red and back to white.

0
Ambient Orb Part 1 - NeoPixel Fade from White to Red and Back
Shivani Kannan - https://youtu.be/6touOvXbk6E
0

Reflection

  • I enjoyed learning how to solder. However, I feel like I relied too much on Chat Gpt because of the Particle Cloud function and the manipulation of the color values in this project. I am confident with the logic of setup and loop without it, but including the particle cloud function meant some parts of the code moved to set up, which was a bit confusing.
  • I was also excited about connecting to IFTT and still want to (hopefully, there is a workaround, or we decide to subscribe to it).

x
Share this Project


About

Create an ambient calendar alert using a neo pixel strip.