Created
May 19, 2014 20:08
-
-
Save peterhellberg/dd6686f614bfd2e216e2 to your computer and use it in GitHub Desktop.
Controlling the D7+RGB leds on the Spark Core over HTTP
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 the pins we're going to call pinMode on | |
int led = D7; // This one is the built-in tiny one to the right of the USB jack | |
int r = 0; | |
int g = 0; | |
int b = 0; | |
// This routine runs only once upon reset | |
void setup() { | |
pinMode(led, OUTPUT); | |
Spark.function("on", on); | |
Spark.function("off", off); | |
Spark.function("rgb", rgb); | |
} | |
void loop() { | |
// Do nothing | |
} | |
int on(String args) { | |
digitalWrite(led, HIGH); // Turn ON the LED pin | |
} | |
int off(String args) { | |
digitalWrite(led, LOW); // Turn OFF the LED pin | |
} | |
int rgb(String args) { | |
int c1 = args.indexOf(","); | |
if(c1>-1){ | |
RGB.control(true); | |
int c2 = args.indexOf(",", c1+1); | |
int nr = args.substring(0, c1).toInt(); | |
int ng = args.substring(c1+1, c2).toInt(); | |
int nb = args.substring(c2+1).toInt(); | |
if(nr >= 0 && nr < 256) { r = nr; } | |
if(ng >= 0 && ng < 256) { g = ng; } | |
if(nb >= 0 && nb < 256) { b = nb; } | |
} | |
// red, green, blue, 0-255 | |
RGB.color(r,g,b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment