Arduino Serial Buffer Clear

Arduino Serial Buffer Clear Average ratng: 4,9/5 2144 votes
Arduino clear serial buffer
  1. Arduino Clear Serial Monitor
  2. Arduino Clearing Serial Buffer

Hi, Scott here from Salem. My program goal. Press 1 on the key board and an led lights up on the arduino. Press 2 and it goes off.

Arduino Clear Serial Monitor

Sets the number of bytes to buffer before calling serialEvent() Syntax. The text of the Arduino reference is licensed under a Creative.

Buffer

Press anything else and the command port prints out 'invalid'. I then want to clear the serial port to erase anything else, because if I press a bunch of numbers e.g. 3456, it prints out invalid several times.

Arduino Clearing Serial Buffer

I would like it to print out invalid only once. I read that Serial.flush no longer works. I have tried byte = discard Serial.read but this does not work. Can someone help me with how to flush the serial port of the remaining data? Here is the code.