- #1
- 962
- 667
This Arduino sketch is supposed to wait for a number and then print it back with a message. But for some reason its gets an extra "0" from the TTY each time I actually type a number. There is about half second delay before the "0" is responded to.
Here is what happens in the TTY:
I can read and discard the "0" as per the commented line #11 --- but that doesn't remove the small delay.
How can I get rid of the extra delay?
Code:
int num;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
Serial.print("Enter a number: ");
while(Serial.available()==0){}
num=Serial.parseInt();
//Serial.parseInt(); // <---- Tried reading and discarding the "0". Well, that works -- but the delay remains.
Serial.println(num);
Serial.print("Your number is: ");
Serial.println(num);
Serial.println("=====\n");
}
Here is what happens in the TTY:
Code:
Your number is: 1
=====
Enter a number: 0
Your number is: 0
=====
Enter a number: 22
Your number is: 22
=====
Enter a number: 0
Your number is: 0
=====
Enter a number:
I can read and discard the "0" as per the commented line #11 --- but that doesn't remove the small delay.
How can I get rid of the extra delay?
Last edited: