Arduino Serial Buffer Clear

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. Press anything else and the command port prints out 'invalid'. Codevisionavr Serial Experiments.

I then want to clear the serial port to erase anything else, because if I press a bunch of numbers e. Konkani Baila Songs Mp3. g. 3456, it prints out invalid several times. 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.

How to flush the input serial buffer in Arduino? How to discard the rest of data from the serial input buffer? Arduino-uno serial. Share improve this question. Driver Intel 965 Express Chipset Family here. Nov 09, 2016 SparkFun Electronics. How to clear out or flush the arduino serial buffer. I then want to clear the serial port to erase anything else.

Arduino Flush