Animated Particle tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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