// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D3
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int fadeTime = 1000 * 60 * 1;
long timeStart = -1;
bool timerStarted = false;
void setup() {
strip.begin();
strip.show();
Particle.function("LightUp", handleLightUp);
}
void loop() {
if (timerStarted == true) {
long timeNow = millis();
long timeElapsed = timeNow - timeStart;
if (timeElapsed < fadeTime) {
int colorValue = map(timeElapsed, 0, fadeTime, 0, 255);
int r = colorValue;
int g = 25;
int b = 25;
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, r, g, b);
}
strip.show();
} else {
timerStarted = false;
for (int k=256; k>=0; k--){
for (int i=0; i<strip.numPixels();i++){
strip.setPixelColor(i,255,0,0);
strip.show();
delay(150);
}
}
}
}
else {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 255);
strip.show();
delay (150);
}
}
}
int handleLightUp (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. .