Hello everyone!
I don't know why but my Arduino Testprogram does not work like it should:
void setup() {
Serial.begin(9600);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
Serial.println("Number of LED1 blinks? ");
while (Serial.available()==0){}
b1 = Serial.parseInt();
Serial.println("Number of LED2 blinks? ");
while (Serial.available()==0){}
b2 = Serial.parseInt();
It is just a test where I am asking in the serial monitor for an input.
What now happens is, that there is the first question: "Number of LED1 blinks?"
after the Input, the second question appears and shortly after the program starts (the void loop) without waiting for the input
I'm going to guess you have the monitor's line ending set to something other than no line end, so the presence of line end character/s is making it fail the second test.
Your line ending in the Serial Monitor is set to "Both NL & CR" (or you send more then just numbers when you send you input (including spaces). parseInt() breaks on the NL (new line) but that leaves the CR in the buffer.
The line end character/s which are the flags that your integer has ended, are also characters in their own right so they count towards the second "while (Serial.available()==0)" test not being 0, even though you only typed one key.
In other news, it may be important to you one day that Serial.parseInt() is a blocking function. You may have noticed a lag in your example until the timeout kicked in; I did.
If it matters one day, eg where the responsiveness of buttons is crucial, it would behoove you to read Robin2's serial tutorial.