Hello there!
Today I got a very weird issue while trying to test the Serial Communication for another project.
First of all: I'm using an Arduino Mega (JOY-IT Clone) hooked up via usb and this is basically my code:
void setup() {
Serial.begin(9600);
Serial.flush();
Serial.println("Ready");
}
void loop() {
if (Serial.available() > 0) {
Serial.println(Serial.available()); //just for debugging
Serial.println(Serial.parseInt()); //printing the entered number
Serial.println(Serial.available()); //just for debugging
}
}
I would have expected something like this when I sent for example 4 through the serial monitor:
1
4
0
But If I type in any number I get:
1
<my entered number>
1
1
And after a delay of a half to a full second it adds:
0
0
So the total output is:
1
<my entered number>
1
1
0
0
I can't explain to me how this happens and didn't found anything on the internet like this
Pls reply soon
Xilef