Ok,
Am following this example:
And have a working example that extracts data from a homeserver page and feeds it into the Serial Monitor using Arduino Uno and 1.0.5
My question is, how is this data held in Arduino code and, therefore, how can I parse/convert it into usable variables.
The website displays a comma separated series of numbers - eg 34,55,65
I want to convert these into values that feed three variables that'll let me control LEDs using these, ie:
int ledRed = X
int ledGreen = Y
int ledBlue = Z
Am thinking it's extracted and fed to the serial monitor using this loop:
void loop() {
while (client.available()) {
char c = client.read();
Serial.write(c);
}
But a bit at a loss as to where I should start to parse into usable data
Comma delimited servo/serial code that might be adapted for client use.
//zoomkat 3-5-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-delomit-test-22-dual-input"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like 700, or 1500, or 2000,
//or like 30, or 90, or 180,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >0) {
Serial.println(readString); //prints string to serial port out
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
//do stuff with the captured readString
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}