digitalRead() condition in 'while' loop not triggering

Hey all,

I have written a piece of code that's job is to extend the actuator (extendActuatorFunction()) and then wait until it either times out after 30 seconds (extendingCounter) or until it hits the endstop switch (extendedEndstop) and then stop the actuator (stopActuator()).

  /* EXTEND THE ACTUATOR */
  extendActuatorFunction();

  /* RESET EXTENDING COUNTER */
  extendingCounter = 0;

  /* WAIT FOR THE LINEAR ACTUATOR TO EXTEND */
  while (extendingCounter < 30 && digitalRead(extendedEndstop == LOW))
  {
    Serial.println(digitalRead(extendedEndstop)); //testing
    delay(1000);
    extendingCounter++;
  }

  /* STOP THE ACTUATOR */
  stopActuator();

All the variable are initialized as integers with a value of '0' at the top of the code.

If the counter reaches 30 it jumps out of the 'while' loop and carries down the program as it should, but if the endstop is hit before 30 seconds has elapsed it carries on running the 'while' loop until the counter hits 30.

Why is this happening? I added in the Serial.println(digitalRead) in the 'while' loop to test the switch is working correctly (returning '0' when not triggered and '1' when triggered) and it's working great.

Any help with this would be great, thanks.

Zeb

Also forgot to mention that it is an ESP32 Development Board that I am using.

(digitalRead(extendedEndstop) == LOW)

Look at the digitalRead closely. What pin is it reading?

(digitalRead(extendedEndstop) == LOW)

Ah, thanks guys! What a rookie mistake...

Thanks again, Zeb.