12345 incomming
123412345 mode
3412345 func
5123412345 var
How do you know which line represents which value? You should have something like:
Serial.print("incoming: [");
Serial.print(incoming);
Serial.println("]");
so that you KNOW what is being stored in each variable.
char incoming [4] ;
You are trying to store 5 elements in an array sized to hold 4.
Serial.flush();
Throwing away random amounts of unread data is always a good idea. NOT!
All of you character arrays need to be NULL-terminated before they will print properly. None of them currently are.
12345 incomming
123412345 mode
3412345 func
5123412345 var
How do you know which line represents which value? You should have something like:
Serial.print("incoming: [");
Serial.print(incoming);
Serial.println("]");
so that you KNOW what is being stored in each variable.