I'd prefer to not use a delimiter. This is for an ME control systems class and I don't want to have to tell me professor to setup the serial monitor a certain way before he runs it, but it I have to than so be it.
If changing the serial monitor setup is the main issue with not using a delimiter, then use a delimiter that is typed in the serial monitor at the end of the data. the below uses a , as the delimiter and no default serial monitor change is required. Just tell the professor to type a , at the end of the data and hit the keyboard enter key or click send in 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
}
}
}