Here's another example,
// assumes a format like <???>
// NOTES:
// no checking for buffer overflow
// will hang if ">" never received
// only designed for an app that has nothing else to do
// no null termination of packet as not specifically designed for strings
//
boolean in_packet = false;
char buffer[30];
int bptr = 0;
void loop()
{
while(Serial.peek() == -1) {}; // wait for a character
char c = Serial.read(); //reading from the serial
if (c == '<') { // check for start of packet char, if not then ignore
bptr = 0;
in_packet = true;
while (in_packet) {
if (Serial.available()) {
incomingData = Serial.read();
if (c == '>') {
handleData();
in_packet = false; // end of packet
} else {
buffer[bptr++] = c;
}
}
}
}
}
void handleData () {
// deal with the data here
}
Rob