//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
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .