// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D4
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int redValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 0; // Full brightness for an Cathode RGB LED is 0, and off 255
unsigned long lastFade = 0;
void setup() {
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
// Particle.function("fade_up", colorFadeUp);
// Particle.function("to_red", colorFadeRed);
// Particle.function("fade_out", colorFadeOut);
Particle.function("time input", colorSeq);
Particle.variable("Red", redValue);
Particle.variable("Green", greenValue);
Particle.variable("Blue", blueValue);
}
void loop() {
}
int colorSeq(String command) {
unsigned long t = command.toInt();
uint64_t wait = t * 1000;
uint32_t c;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
lastFade = millis();
while(millis() - lastFade <= t * 60 * 1000) {
redValue += 4;
greenValue += 4;
blueValue += 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
}
lastFade = millis();
while(millis() - lastFade <= t * 60 * 1000) {
greenValue -= 4;
blueValue -= 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
}
lastFade = millis();
while(millis() - lastFade <= t * 60 * 1000) {
redValue -= 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
}
colorAll(0, wait);
return 1;
}
int colorFadeUp(String command) {
int t = command.toInt();
uint64_t wait = t * 1000;
uint32_t c;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
unsigned long now = millis();
while(now - lastFade <= t * 60 * 1000) {
redValue += 4;
greenValue += 4;
blueValue += 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
now = millis();
}
}
int colorFadeRed(String command) {
int t = command.toInt();
uint64_t wait = t * 1000;
uint32_t c;
redValue = 255;
greenValue = 255;
blueValue = 255;
unsigned long lastFade = 0;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
unsigned long now = millis();
while(now - lastFade <= t * 60 * 1000) {
greenValue -= 4;
blueValue -= 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
now = millis();
}
return 1;
}
int colorFadeOut(String command) {
int t = command.toInt();
uint64_t wait = t * 1000;
uint32_t c;
redValue = 255;
greenValue = 0;
blueValue = 0;
unsigned long lastFade = 0;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
unsigned long now = millis();
while(now - lastFade <= t * 60 * 1000) {
redValue -= 4;
c = strip.Color(redValue, greenValue, blueValue);
colorAll(c, wait);
now = millis();
}
colorAll(0, wait);
return 1;
}
// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint64_t wait) {
uint16_t i;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(wait);
}
// Button press interrupt service routine
void buttonPressInterrupt(){
buttonPressFlag = true;
}
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. .