changing increment within for loop not working

I am trying to step through an array I have created to hold the increment values for PWM microstepping 32 equal positions.

I have checked all the references I can find on changing the increment value within a for loop.
This is the code snippet which verifies, compiles and uploads to a pro mini.

The PWM value does not change when I run the sketch.
The buttonpush() function is called and returns. I have pin 13 LED to monitor this.

I wonder if anyone has any suggestions on where I have not understood how to do this.

Thanks if you can help.
With the code just using the increment of s1--, the sketch runs fine and that is how I got the values to put in the array using a scale on the wall and a laser on the motor axis.

void loop()
{ 
//start pattern halfway through mstep0
  int mstep = 31;
  for (int s1 = 254; s1 >=0; s1-(inc[mstep]))
  { analogWrite(pinCpwm,s1);
    delay(speeddelay);
    buttonpush();
    mstep--;
  }
  delay(speeddelay);
for (int s1 = 254; s1 >=0; s1-(inc[mstep]))

The final part of this for statement does not assign a new value to s1

You haven't shown the code which shows what inc[mstep] actually is, but if it is properly defined somewhere, then this should work

for (int s1 = 254; s1 >=0; s1 = s1-(inc[mstep]))

and this should work too

for (int s1 = 254; s1 >=0; s1-=(inc[mstep]))

look at your for() loop.

Here is a generic one:

for( int i=0; i<10; i++ )
{
}

Here is the same loop:

for( int i=0; i<10; i+=1 )
{
}

You are not assigning a new value to your loop counter. :slight_smile:

Assuming your inc array is correct you want this:

for (int s1 = 254; s1 >=0; s1-=(inc[mstep]))
{
  //...stuff
}

Thank you for both those helpful responses.
I do remember when working through the examples in tutorials about having loops not work using variations on the increment which used a counter within the loop, I tried the inc = inc +1 method at that time.
So I am now confidently going to alter the code as you suggest, since the compiler obviously can do this sort of thing.
I am doing it this way so I have a quicker and more flexible way to try different microsteps and PWM values.
I think it would be easier to finally have a sketch that used a for loop through an array of actual PWM values. I may need 20 arrays though, if each winding/polarity change has different characteristics.