Hello, i have a problem and hope someone can help me.
I send a string value over a serialport to my arduino.
The string looks like:
string MotorSteps = A1000>B2001>C123>D2000>;
I need an easy way to get the value between A >, B >, C >, D > of MotorSteps, (in this case: 1000, 2001,123,2000) and store the four values to four int variables. (int step1, int step2, int step3, int step4)
Very simple delimiting test code for testing with the serial monitor.
//zoomkat 3-5-12 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter
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
}
}
}