Running a part of code while another one is running

The “wave” function creates a wave with the LEDs I have connected to the arduino, but the delays in the function make it so that the other code has to wait for the wave to finish. I included a comment on line 68 near the end that explains a bit more.

#include <Arduino.h>

#define LED 13
#define LED2 2
#define LED3 3
#define LED4 4
#define LED5 5
#define LED6 6
#define LED7 7
#define LED8 8
#define LED9 9
#define LED10 10
#define LED11 11
#define BUTTON 12

int buttonState = 0;
int whichMode = 0;
void setup()
{
 Serial.begin(9600);
 pinMode(BUTTON, INPUT_PULLUP);
 pinMode(LED, OUTPUT);
 pinMode(LED2, OUTPUT);
 pinMode(LED3, OUTPUT);
 pinMode(LED4, OUTPUT);
 pinMode(LED5, OUTPUT);
 pinMode(LED6, OUTPUT);
 pinMode(LED7, OUTPUT);
 pinMode(LED8, OUTPUT);
 pinMode(LED9, OUTPUT);
 pinMode(LED10, OUTPUT);
 pinMode(LED11, OUTPUT);
}
void ledControl(int whichLED, bool on, int ledDelay){
 if (on)
   digitalWrite(whichLED, HIGH);
 else
   digitalWrite(whichLED, LOW);
 delay(ledDelay);
}
void wave(){
 ledControl(LED, true, 100);
 ledControl(LED2, true, 100);
 ledControl(LED3, true, 100);
 ledControl(LED, false, 0);
 ledControl(LED4, true, 100);
 ledControl(LED2, false, 0);
 ledControl(LED5, true, 100);
 ledControl(LED3, false, 0);
 ledControl(LED6, true, 100);
 ledControl(LED4, false, 0);
 ledControl(LED7, true, 100);
 ledControl(LED5, false, 0);
 ledControl(LED8, true, 100);
 ledControl(LED6, false, 0);
 ledControl(LED9, true, 100);
 ledControl(LED7, false, 0);
 ledControl(LED10, true, 100);
 ledControl(LED8, false, 0);
 ledControl(LED11, true, 100);
 ledControl(LED9, false, 0);
 ledControl(LED10, false, 100);
 ledControl(LED11, false, 100);
}

void loop()
{
 wave(); //this is what I'd like to have running all the time, but without delaying
         //the rest of the loop (the button stuff)

 
 buttonState = digitalRead(BUTTON);
 if (buttonState == LOW){
   whichMode++;
   Serial.println(whichMode);
 }
}

You will need to use an approach based on millis().

In this sticky, you can search for millis, multiple things and state machines to get some ideas.

sterretje:
You will need to use an approach based on millis().

In this sticky, you can search for millis, multiple things and state machines to get some ideas.

thanks, will do!

Several things at a time.

xeon3175x:
So I took a look at the resources you linked, and I was able to get it working with two LEDs, but I have no idea how to implement it into my code.

Please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. That way we can focus on the parts you need help with rather than wasting time on things that you can do.

...R

Robin2:
Please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. That way we can focus on the parts you need help with rather than wasting time on things that you can do.

...R

Sorry, I should've added the code, but thankfully I figured it out right after I posted that.