Go Down

Topic: how do I parse Serial Data only when preceded by.... (Read 344 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.

Nick Gammon

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

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy