I am trying to read a number inputed to the Serial Monitor and store it in a variable. It works the first time through the loop but somehow another number is being inputed. In the code I get a return of:
i = 2341 (the number I typed in. Good!)
Then i = 0 (don't know where this came from.)
I want to save the number inputed in the serial monitor, not the odd 0.
Does hitting ENTER or clicking the SEND button cause another character to be sent?
int i;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.setTimeout(20);
}
void loop() {
while (Serial.available()==0) {}
i = Serial.parseInt();
Serial.print("i= ");
Serial.println(i);
}