For loop counting not working

Hi everyone,

I’m trying to run a task for a fixed number of times that is inputted by the user. For example, the user has input the number 10, so the looop will only work 10 times. All of my counters are working, but I can’t get the loop to stop at the number the user inputs.

In this case, “printCounter” is the user input value. The “sigSate” is an input that tells the program when a state change has happened.

Any help will be greatly appreciated.

sigState = digitalRead(busySig);

if(sigState != lastSigState)
{
  for(int x = 0; x < printCounter; x++)
  {
  delay(350);
  stepper.runToPosition();
  stepper.move(indexLength);
  digitalWrite(relay, HIGH);
  delay(25);
  digitalWrite(relay, LOW);
  }
 lastSigState = sigState;   
}

In this case, "printCounter" is the user input value.

Unfortunately you did not post your whole program so we have no idea how you are getting this value. Please post your whole program.

What do you see if you print printCounter ?

Any help will be greatly appreciated.

Well that would depend on you posting ALL of your code, so that we can verify your assumptions. For instance, "In this case, "printCounter" is the user input value.". There is no proof of that.

We have no idea what value is in indexLength, or even what stepper is.