Created
January 20, 2014 03:38
-
-
Save towynlin/8514510 to your computer and use it in GitHub Desktop.
Spark firmware for setting RGB LED color using the Spark Tinker mobile app's analogWrite on pins A4, A5, and A6.
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
// Default to pinkish | |
int redValue = 255; | |
int greenValue = 33; | |
int blueValue = 121; | |
int countdown; | |
void showColor() { | |
RGB.control(true); | |
RGB.color(redValue, greenValue, blueValue); | |
countdown = 1000; | |
} | |
int updateRGBLEDColor(String pinAndValue) { | |
int pinNumber = pinAndValue.charAt(1) - '0'; | |
int value = pinAndValue.substring(3).toInt(); | |
if (4 == pinNumber) | |
redValue = value; | |
else if (5 == pinNumber) | |
greenValue = value; | |
else if (6 == pinNumber) | |
blueValue = value; | |
showColor(); | |
return 0; | |
} | |
void setup() { | |
Spark.function("analogwrite", updateRGBLEDColor); | |
showColor(); | |
} | |
void loop() { | |
if (0 == countdown) | |
RGB.control(false); | |
if (0 <= countdown) | |
--countdown; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment