Hi everyone!
I am having problems sending an integer number through serial monitor to Arduino UNO.
What I want to do is letting arduino wait until I put a number in the Monitor, then read and use the number to do something in myFun().
I read some tutorials and tried to use Serial.parseInt(). My code:
void loop() {
Serial.println("Enter a value smaller than 4095:");
while (Serial.available()==0 ){
}
int Val = Serial.parseInt();
Serial.println(Val);
//then myFun(Val)
}
The problem is everytime I send a number, the loop() will run two times. The second time seems like a zero is the input, which changes the values in myFun too. For example, when I enter 9 it shows in the monitor:
Blockquote
Enter a value smaller than 4095:
9
Enter a value smaller than 4095:
0
Enter a value smaller than 4095:
Can someone tell me why and how can I prevent this so I can keep the return value in myFun() before I send a new number?
Thanks in advance!