Change delay for millis

Hello!

I have compiled a code for my central lockign system for my car but the only problem I have was with delay function. When button is pressed I want it to do for example: lock doors, beep once, blink 5 times and close the windows or something like that.

//locking
  if (buttonA == HIGH)
   {
    digitalWrite(relaylock, HIGH);
    digitalWrite(relayindicators, HIGH);
    digitalWrite(relaybeep, HIGH);
    digitalWrite(relaywindowup, HIGH);
    delay(150);
    digitalWrite(relaysound, LOW);
    digitalWrite(relayindicators, LOW); 
    delay(300);
    digitalWrite(relaylock, LOW);
    delay(8600);
    digitalWrite(relaywindowup, LOW);
 }

So as you can see, when button is pressed it does several things and after some time it turns off but the delay is long because this is the time needed for switch/relay to be pressed to close the windows, problem is that I cannot interupt this time with another button (maybe with unlock button beacuse I forgot my phone on the sear) so I have to wait the time to pass. I also have a photoresistor that tells of it is dark then it turns on fog lights for 22 seconds.

How can I interrupt the delay, can I use millis and how?

Thanks!

You could make a struct

struct tableStruct
{
  int pin,
  int value,
  unsigned long interval,
};

tableStruct table[] = 
{
  { relaylock, HIGH, 0 },
  { relayindicators, HIGH, 0 },
  { relaybeep, HIGH, 0 },
  { relaywindowup, HIGH, 150 },
  ...
};

With variables to control everything:

bool enable;
int index;

unsigned long previousMillis;
unsigned long interval;

With a millis() timer in the loop()

unsigned long currentMillis = millis();

if( enable)
{
  if( currentMillis - previousMillis >= interval)
  {
    previousMillis = currentMillis;
  
    digitalWrite( table[index].pin, table[index].value);
    interval = table[index].interval;

    index++;
    if( index >= sizeof(table) / sizeof(tableStruct))
    {
      enable = false;
    }
  }
}

Starting the table can be done with:

enable = true;
index = 0;
previousMillis = millis();

When a few items in the struct have a interval of zero, they will be executed one by one every time the loop() runs. That will work, even with a interval of zero.