Arduino Clear Serial

Hi,

  1. Arduino Clear Serial Input Buffer
  • I'm starting to build my first Arduino project but I'm running into some problems with serial communication. I get serial data from the console and store it in a char array called 'data'. Then, when I send a new console message to the Arduino, I want it to clear the existing 'data' array and store only the new data in that array.
  • Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.) flush inherits from the Stream utility class.

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'. 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. 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?Arduino clear serial output bufferSerial
Here is the code;

Created on: 2 August 2012Clear Serial Monitor Arduino DownloadHow To Clear Serial Monitor ArduinoThe Arduino Uno can send data (such as a text message) to the PC over the USB cable. ComponentsAll that is needed is an Arduino Uno board, standard USB cable and PC with the Arduino IDE software installed.


thank you,

Arduino Clear Serial Input Buffer

Scott