Skip to content

Instantly share code, notes, and snippets.

@dmiddlecamp
Created January 20, 2015 20:34
Show Gist options
  • Save dmiddlecamp/6c320e45941b47795066 to your computer and use it in GitHub Desktop.
Save dmiddlecamp/6c320e45941b47795066 to your computer and use it in GitHub Desktop.
Slightly more fancy version with auto-off
#define AUTO_OFF 1 /* minutes */
unsigned int lastOn = 0;
void setup() {
Spark.function("shoutRainbows", nyanHandler);
}
void loop() {
//nothing to see here!
if (lastOn > 0) {
float elapsed = ((millis() - lastOn) / 1000.0) / 60.0;
if (elapsed >= AUTO_OFF) {
nyanHandler("off");
}
}
}
int nyanHandler(String cmd) {
if (cmd == "on") {
Spark_Signal(true);
lastOn = millis();
}
else if (cmd == "off") {
Spark_Signal(false);
lastOn = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment