Shama_Ambient orb
Made by Shama Patwardhan
Made by Shama Patwardhan
Ambient lighting with the Neopixel
Created: November 13th, 2024
With the neopixel, add a Particle Cloud function that fades the strip to red over 1 minute
I started by practicing soldering in class and successfully soldered the NeoPixel strip. Then, I learned how to code the strip to light up all white and eventually experimented with different numbers to achieve various colors. I also practiced lighting up one pixel at a time.
In Step 3, I alternated the RGB colors on every pixel. Finally, I integrated the cloud function to fade the light to red over a minute on command. This last part was a bit tricky, and I had to troubleshoot my code multiple times. The code had some bugs that caused the NeoPixel to either not flash any light or flash only white. Additionally, I struggled to find the call button on the console. I realized I was looking in the wrong place and sending signals to my particle instead of calling the "starttofade" function.
In the end, I'm glad it worked out.
I wasn't able to integrate the IFTTT and the calender aspect of the exercise into the console, but i will troubleshooot in class, and figure it out!
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// This #include statement was automatically added by the Particle IDE.
// Include Particle Device OS APIs
#include <Particle.h>
#define PIXEL_PIN SPI
#define PIXEL_COUNT 7
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
bool fadeToRedActive = false; // Whether the fade to red is active
unsigned long fadeStartTime = 0; // Start time for the fade effect
// Color definitions
const uint32_t OFF = strip.Color(0, 0, 0);
const uint32_t FULL_RED = strip.Color(255, 0, 0);
// setup() runs once, when the device is first turned on
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// Register Particle Cloud function
Particle.function("startFadeToRed", startFadeToRed);
}
// Particle function to initiate fade to red
int startFadeToRed(String command) {
fadeToRedActive = true;
fadeStartTime = millis(); // Record the start time
return 1; // Return success
}
// Function to handle fading to red over 1 minute
void fadeToRed() {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - fadeStartTime;
if (elapsedTime >= 60000) { // 1 minute (60000 ms) has passed
// Set all pixels to full red and stop fading
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, FULL_RED);
}
strip.show();
fadeToRedActive = false; // Stop the fade effect
} else {
// Calculate the fade level from 0 to 255 based on elapsed time
uint8_t fadeLevel = (elapsedTime * 255) / 60000;
// Set each pixel to the progressively faded red color
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(fadeLevel, 0, 0)); // Red with increasing intensity
}
strip.show();
}
}
// Main loop function
void loop() {
if (fadeToRedActive) {
fadeToRed(); // Call fade function if active
}
}
Click to Expand
Ambient lighting with the Neopixel