Go Down

Topic: how do I parse Serial Data only when preceded by.... (Read 418 times) previous topic - next topic

Christopher Overstreet

I would like to analyze incoming serial data looking for...

If "A" comes in then look at the next 8 numbers

do something to first number,
do something to second number,
etc.

If "B" comes in then look at the next 8 numbers

do something to first number,
do something to second number,
etc.
When there is a line break exit this function and start looking for A's and B's again.

I know this isn't that complex, but I am having a lot of trouble figuring it out.  My background is in max-msp.  Any help would be appreciated.
ChristopherO

bubulindo

Code: [Select]

if (Serial.available() >=10) {  //A + 8 numbers + \n

switch(Serial.read()) {
    case 'A': {
        //do something to first number...
        //do something to second number...
        //etc...
        if (Serial.read() == '\n') {
            //things are great, accept the command
            }
        break;
        }
    case 'B': {
        //do something to first number...
        //do something to second number...
        //etc...
        if (Serial.read() == '\n') {
            //things are great, accept the command
            }
        break;
        }
}//end switch
}//ed if
This... is a hobby.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up