Skip to content

Instantly share code, notes, and snippets.

@towynlin
Created January 20, 2014 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/8514510 to your computer and use it in GitHub Desktop.
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.
// 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