/*
Forum: https://forum.arduino.cc/t/is-there-better-way-to-remove-n-character-from-serial-buffer-while-executing-serial-readbytesuntil-function/1197775
Wokwi: https://wokwi.com/projects/383447769467596801
*/
//char myData[8];
char myData[8];
void setup()
{
Serial.begin(9600); //to enable serial link between PC, SM, IDE, UNO
Serial.println("Input 1234.56 ...");
}
int count;
void loop()
{
byte n = Serial.available();
if (n != 0) //there is at least one character in Buffer
{
byte m = Serial.readBytesUntil('\n', myData, sizeof myData - 1); //'\n' is not saved; m =
myData[m] = '\0'; //insert null-chracter at the end of string array
Serial.read(); //to remove '\n' charcater
//---- reconstruct 1234,56 from the recived ASCII coded 1234.56 -----
float y = atof(myData); //atof()= ASCII to float function
count++;
Serial.print(count);
Serial.print("\t");
Serial.println(y, 2);
}
}