Serial.write(27); // ESC command Serial.print('2J'); // clear screen command Serial.write(27); Serial.print('H'); // cursor to home command But it doesn't work. I also found a solution like Serial.println; but that solution (cheat as they called it) will only work on a serial monitor. So is there any possible solution to clear the display. It is not clear what do you really want to do. Anyway, please note: In your C# code, if you enter, for instance, '1' in your TextBox then four bytes are sent to the serial line: three 0s and a single 1 (the 0s won't be handled by your Arduino code). In your Arduino code you didn't check if Serial.read returns -1 (i.e. No data available).
Arduino Clear Serial Monitor Command
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?Here is the code;
Arduino Clear Serial Monitor
thank you,Scott