Shivani Kannan - Ambient Orb
Made by Shivani Kannan
Made by Shivani Kannan
Create an ambient calendar alert using a neo pixel strip.
Created: November 13th, 2024
To create an ambient calendar alert using a neo pixel strip.
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
// 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
Create an ambient calendar alert using a neo pixel strip.