while function not working

why do this code read only the first "while" function.

int redLedPin = 10;
int redTimeOn;
int redTimeOff = 1000;
int cntt = 0;
int voltVal;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(redLedPin, OUTPUT);
  
  Serial.println("Enter volt value := ");
  while (Serial.available() == 0){ }
  voltVal = Serial.parseInt();  
  
  Serial.println("Enter sleep time := ");
  while (Serial.available() == 0){ }
  redTimeOn = Serial.parseInt();
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("Led_On pin ");
  Serial.println(cntt++);
  analogWrite(redLedPin, voltVal);
  delay(redTimeOn);
  analogWrite(redLedPin, 0);
  delay(redTimeOff);  
}

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

The basics of Arduino:

  • The function setup() is executed exact 1 time at start of your sketch.
  • Then the function loop() is executed over end over...

You see one input because your Serial.read() is in setup!

RudolfAtRTC:
The basics of Arduino:

  • The function setup() is executed exact 1 time at start of your sketch.
  • Then the function loop() is executed over end over...

You see one input because your Serial.read() is in setup!

Did you notice the two while loops and two Serial.parseInt()s in setup() ?

My suspicion is that he has a Line Ending set in the Serial monitor so the second while condition is met straight away

Add debug output and flush the input buffer of any characters left by the .parseInt() calls:

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(redLedPin, OUTPUT);

  Serial.println("Enter volt value (0-255) := ");
  while (Serial.available() == 0) { }
  voltVal = Serial.parseInt();
  Serial.print("voltVal = ");
  Serial.println(voltval);
  while (Serial.available()) Serial.read();  // You forgot to empty the input buffer

  Serial.println("Enter sleep time in milliseconds:= ");
  while (Serial.available() == 0) { }
  redTimeOn = Serial.parseInt();
  Serial.print("redTimeOn = ");
  Serial.println(redTimeOn);
  while (Serial.available()) Serial.read();  // You forgot to empty the input buffer
}

thank you guys... so foolish of me!