I'm trying to write a program at the moment so i can send a short message (e.g. 12:8:) from a computer (program written in processing) to a arduino (acting as server), I've run into a bit of trouble though, i need the arduino to interpret the message received into two, if that makes sense, for example, if the computer sends 12:8: i need the arduino to see it as
int val1 = 12;
int val2 = 8;
i put the : there because i thought i could tell the arduino to read the buffer upto the : but i can't find out how! the processing one i can write fine, just can't work out how to write the arduino one
How are you sending it?- I mean what format of message? You could try sending it as an HTTP GET say, and have the server code parse it by looking for the : then look back to the previous space and forward to the next space, that would give you the two digits.
A simple way to use the : as a delimiter which you might incorporate in your client code.
//zoomkat 3-5-12 simple delimited ':' string
//from serial port input (via serial monitor)
//and print result out serial port
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like wer,qwe rty,123 456,hyre kjhg,
//or like hello world,who are you?,bye!,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ':') {
//do stuff
Serial.println(readString); //prints string to serial port out
readString=""; //clears variable for new input
}
else {
readString += c; //makes the string readString
}
}
}