Introduction: RGB With SparkCore and Curl
Controlling a common RGB-LED with a Spark core and curl.
The complete code is attached.
Step 1: Parts and Wiring
To light up a simple rgb-LED you need:
- 1 Spark.io Spark Core
- 1 rgb-LED
- 3 220-Ω resistors
- 1 jumper
- 1 breadboard
Please wire all parts according to the scheme.
Step 2: Code
Hook up the core and claim it.
Transfer the code via the Spark core IDE.
This is the core part of the code parsing a list of numeric arguments separated by ',' into an array of double values:
for(int i=0;i<=length;i++)// parse all parts of args between the separators {
if(args.charAt(i)==separator || i == length){ String substring = args.substring(from, i); int bufSize = 1+ substring.length(); char buffer[bufSize]; substring.toCharArray(buffer, bufSize); double value = atof(buffer); *(allValues + allValuesCount)=value; allValuesCount++; if(i < length) // next substring beyond separator from = i+1; } }
Attachments
Step 3: Command
The call on a terminal-application for a yellow LED would be:
curl https://api.spark.io/v1/devices/0123456789abcdef01234567/changeColor \ -d "access_token=1234123412341234123412341234123412341234"\ -d "args=255,255,0”
Of course, the device-ID and the access-token have to be taken from the device you are working on.
Comments
9 years ago on Introduction
Nice!