Controlling for loop timing without a delay()

Hi, same as the title really. I have built an LED light application which is controlled via a GUI in C#. Four LED strips with 12 LED's each are connected to one Arduino Mega and an LED wheel is connected to another Mega. I am writing to to serial ports when I am adjusting the trackbar and selecting the test buttons.
After a few different iterations I am now almost finished this, however, the LED colour wheel is spinning which is controlled by a for loop using a delay and if I adjust the trackbar while it is in the delay it is obviously lagging behind.

int ledPins[] = {
  9,8,7,6,5,4,3,2,14,15,16, 17};


void buttonTest(byte dummy)
{
for(int i= 0; i < 12; i++)
  {
    digitalWrite(ledPins[i], HIGH);
    delay(250);
  }
}

I send the RGB command and PWM value across as a string in packets which I seen PaulS from
here using, this totally changed my program and got it working so much better than it was before. Example: .

Would I be able to get millis() to control the timing of a for loop?

Thanks.

Would I be able to get millis() to control the timing of a for loop?

That is something only you are able to assess. Personally, I could. The blink without delay example provides some information. You'll obviously need to get rid of the for loop and implement a state machine that is tested on every pass through loop().

if(currentMillis - previousMillis >= interval)[color=#222222][/color]
  {[color=#222222][/color]
    digitalWrite(ledPins[i], LOW);
[color=#222222]    i ++ ;[/color]
[color=#222222]      if (i >12){[/color]
[color=#222222]          i = 1;    
[/color]
[color=#222222]    }[/color][color=#222222][/color]
[color=#222222]    previousMillis = currentMillis;[/color][color=#222222][/color]
[color=#222222]  }[/color]

could this replace the for loop ?

increment i each time the interval is met ?

can anyone point me to the instructions on the new form ?

what the heck did I do ?

dave-in-nj:

if(currentMillis - previousMillis >= interval)

digitalWrite(ledPins[i], LOW);
   i ++ ;
     if (i >12){
         i = 1;    
   }
   previousMillis = currentMillis;
 }




could this replace the for loop ?


increment i each time the interval is met ?

ZeuSou7x:
I will show you what I have tried and maybe you can tell me where I am going wrong.

You must post the entire program, not just little snippets out of context.

...R

what the heck did I do ?

It looks like you used the Copy for forum option in the IDE. That was a misguided attempt that has never worked. But, like all "features", once added can never be removed, no matter how useless.