[SOLVED]Flush serial input buffer

surepic:
Then why there is 1 char left in the buffer and that char is not “z” or any other letter but “b”? Why all other chars were cleared except “b”?

Because you are only reading one thing:

 if(Serial.available()){
  Serial.write(Serial.read());
  Serial.println(" left in serial buffer");}

If you had put "while" instead of "if" you would have seen more things. Not all of them, because some of them would arrive in the future.

1 Like