Created
January 20, 2015 20:34
-
-
Save dmiddlecamp/6c320e45941b47795066 to your computer and use it in GitHub Desktop.
Slightly more fancy version with auto-off
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
#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