Please help replacing delay() with millis()

Please help

what i want to do for replacing delay() with millis() in this sketch,

int outputArray1[] = {8, 9, 10, 11, 12, 13,A0,A1,A2};
int outputArray2[] = {A2,A1,A0,13, 12, 11, 10, 9, 8};

int delayTime = 300;

int button1 = 2;
int button2 = 3;
void setup() {
  //initialise ledArray as outputs
  for (int i = 0; i < 10; i++) {
    for ( int j = 0; j < 10; j++) {

      pinMode(outputArray1[i], OUTPUT);
      pinMode(outputArray2[i], OUTPUT);
      pinMode(button1, INPUT);
      pinMode(button2, INPUT);
    }
  }
}
void loop() {
  if (digitalRead(button1) == HIGH) {
    //turn LEDs on from 0-9
    for (int i = 0; i <= 9; i++)
    {
      digitalWrite(outputArray1[i], HIGH);
      delay(delayTime * 6);

    }

    //turn LEDs off from 9-0
    for (int i = 9; i >= 0; i--)
    {
      digitalWrite(outputArray1[i], LOW);
      delay(delayTime);
    }
  }

  if (digitalRead(button2) == HIGH) {
    //turn LEDs on from 0-9
    for (int j = 0; j <= 9; j++)
    {
      digitalWrite(outputArray2[j], HIGH);
      delay(delayTime * 6);

    }

    //turn LEDs off from 9-0
    for (int j = 9; j >= 0; j--)
    {
      digitalWrite(outputArray2[j], LOW);
      delay(delayTime);
    }
  }

}

So, what have you tried?

PS Not everything is an int :wink:
PPS An array can have two dimensions.

The first thing to appreciate that you cannot simply drop in a bunch of code that uses millis() to do the same thing as delay() if you want the code to be non blocking. You will also need to restructure the program so that loop() keeps running freely. If you had millis() timing in mind when designing the program then you would have done it differently so take a deep breath and start again.

So, how do you structure the new program ? Looking at the existing program we can see that it is either turning the LEDs on or off in sequence and that the delay() period is different when turning on the LEDs and that a different set of LEDs is used depending on the button that has been pressed. At any one time the program will be doing the following

1 - waiting for input 1
2 - turning on LED set 1
3 - turning off LED set 1
4 - waiting for input 2
5 - turning on LED set 2
6 - turning off LED set 2

I assume that the reason for using millis() for timing is so that steps 1,2,3 and 4,5,6 can occur independently. Start by dealing with 1,2,3 alone. Only one of them will be happening at a time, ie the program will be in one of 3 states. A classic "state machine"

Some pseudo code for 1,2,3

state1 = 0
start of loop()
  switch(state1)
    case 0 - waiting for input
      if button1 becomes pressed set state to 1
       turn on the first LED
       save the start time
    end of case
    
    case 1
      if time now - start time >= period
        turn on the next LED
        save the current time as start time
        if all LEDs on set state to 2
        turn off the first LED
      end if
    end of case
    
    case 2
      if time now - start time >= period
        turn off the next LED
        save the current time as start time
        if all LEDs off set state to 0
      end if     
    end of case  
    
  end of switch
end of loop()

Note the use of switch/case. You could use if/else but I find switch/case much more readable. Note also that the code does not prevent loop() running freely so you could have a second switch/case to control the second button and LEDs

As suggested there are ways to use arrays to tidy the code but I suggest that you get a basic version working first

If you have not already done so then look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Thanks,

i will try

Moderator edit: over-quote removed