Skip to content

Instantly share code, notes, and snippets.

@monkbroc
Last active December 24, 2015 14:01
Show Gist options
  • Save monkbroc/7193985b5f37643e8046 to your computer and use it in GitHub Desktop.
Save monkbroc/7193985b5f37643e8046 to your computer and use it in GitHub Desktop.
Animated Particle tree
#include "application.h"
char number = -1;
char maxNumber = 2;
bool alt = false;
int setNumber(String value) {
EEPROM.write(0, value.toInt());
return 0;
}
void blinkNextLED() {
if(number == maxNumber) {
Particle.publish("tree_led/0");
} else {
Particle.publish(String("tree_led/") + String(number + 1, DEC));
}
}
void blinkLED(const char *event, const char *data) {
if(number == 0) {
RGB.color(RGB_COLOR_YELLOW);
delay(200);
RGB.color(0);
delay(200);
RGB.color(RGB_COLOR_YELLOW);
} else {
if(alt) {
RGB.color(RGB_COLOR_RED);
} else {
RGB.color(RGB_COLOR_GREEN);
}
alt = !alt;
}
delay(200);
RGB.color(0);
blinkNextLED();
}
void setup() {
RGB.control(true);
Particle.function("number", setNumber);
number = EEPROM.read(0);
Particle.subscribe(String("tree_led/") + String(number, DEC), blinkLED);
if(number == 0) {
blinkNextLED();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment