Delay in "while loop"...

Hello. im trying to make a steppermotor run when I press a button and until the value from a photoresistor exceeds 300.
the problem is that it takes half a second from when the value is higher than 300 until the motor stops.

Here is the code:

void loop()
{
digitalWrite(led, HIGH); // Turn the LED on
int c = analogRead(A0);
Serial.println(c);
buttonState = digitalRead(buttonPin);

if ((buttonState == HIGH) && (c < 300)) {
Serial.println("Press");
while (c < 300) {
c = analogRead(A0);
Serial.println("Run");
myStepper.step(stepsPerRevolution);

Thanks in advance!

Hello and welcome.

The code you have posted is incomplete and not correctly formatted.

Before you do anything else please take a moment to read General guidance
And How to use this forum
Especially item #7 on posting code.

You need to get away from using delay and from using while loops, both of them will make your code slow and unresponsive. These tutorials will help you:
Using millis for timing
Demonstration for several things at the same time

Enjoy :slight_smile:

I will do that! Thanks