Multiple inputs using Serial.available()

Hello,

i'm a complete noob in coding.
I write because i didn't find an particular answer to my my problem.

Question:

My task is to "tell" to each of two ports to flash the its LED, as many times in an input.
I built a code in which i i'm "telling" it to stop running until i input the first value
and then stop running until i enter the second value.
The problem is that it accepts the first input and ignores the second one and starts running the code that comes after.

the code works fine with the delay() command.
I would very much appreciate the answer.

The code piece*:
*while the whole code is attached only the relevant piece follows.

Serial.println("#times for blue led to blink: ");
while (Serial.available() == 0 ){}
BlueLedBlinkTimes=Serial.parseInt();

Serial.println("#times for green led to blink: ");
while (Serial.available() == 0 ){}
GreenLedBlinkTimes=Serial.parseInt();

analogInput.ino (1.05 KB)

The problem is that it accepts the first input and ignores the second one and starts running the code that comes after.

What have you got Line ending set to in the Serial monitor ?

Any line ending characters on the first input will still be in the buffer when the second available() happens so the code will move on without further user input

Before these lines:

    while (Serial.available() == 0 ){}

Add this line:

    while (Serial.available()) Serial.read();  // Flush old input characters

Thanks both!
It works perfect, John.

I may have misunderstood the documentation but
does Serial.read() make the buffer use only one byte
before the next input happens?

Serial.read() reads only one character, if that's your question...

Indeed that was my question. Thanx!
All was answered.