Blinking patterns without delay

Im working on a project that involves 20 lighting zones blinking in different patterns, I have allready written a few patterns, but in order for in to function I need to work the delay function out of the code.
Could anyone help me with this

Thank you

Daan

Code:

const int buttonPin = 4;     


int oldButtonVal = 0;
int var = 1;
int nPatterns = 4;
int lightPattern = 1;


int buttonState = 0;         


void setup() {

    for (int pin = 26; pin <= 46; pin++ ){
    pinMode(pin, OUTPUT);
    digitalWrite(pin, HIGH);
  }


    pinMode(buttonPin, INPUT);
    digitalWrite(buttonPin, HIGH); 
      pinMode(8, OUTPUT);
}

 void loop() {
  digitalWrite(8, HIGH);
   // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
   int buttonVal = digitalRead(buttonPin);
  if (buttonVal == LOW && oldButtonVal == HIGH) {//a
    lightPattern = lightPattern + 1;
  }
  if (lightPattern > nPatterns) lightPattern = 1;
  oldButtonVal = buttonVal;
 
  switch(lightPattern) {
    case 1:
     allon();
      break;
    case 2:
      alloff();
      break;
      case 3:
      allblink();
      break;
    case 4:
     quadblink();
      break;
      case 5:
     randa();
      break;
  }
}void allon() {
  for (int pin = 26; pin<= 46; pin++){
    digitalWrite(pin, LOW);  
  }
}

void alloff() {
  for (int pin = 26; pin<= 46; pin++){
    digitalWrite(pin, HIGH);  
  }
}

void snake() {
  for (int i = 0; i <=19; i++){
    for (int pin = 22; pin<= 41 - i; pin++){
      digitalWrite(pin - 1, HIGH);
      digitalWrite(pin, LOW);
      delay(160);
    }
  }
}

void allblink(int times){
  for (int i = 1; i <= 4 * times; i++){
    var = (var + 1) % 2;
    for (int pin = 22; pin <= 41; pin++){
      if(pin % 2 == var){
        digitalWrite(pin, LOW);  
      }else{
         digitalWrite(pin, HIGH);
      }
    }
    delay(250);
  }
}

void quadblink(int times) {
  for (int i = 1; i <= 20 * times; i++){
    var = (var + 1) % 4;

    for (int pin = 22; pin <= 41; pin++){
      if(pin % 4 == var){
        digitalWrite(pin, LOW);  
      }else{
         digitalWrite(pin, HIGH);
      }
    }
    delay(250);
  }
}

void randa(int times) {
  for (int i = 1; i <= 100 * times; i++){
    digitalWrite(random(22,42), LOW);
    digitalWrite(random(22,42), HIGH);
    delay(100);
  }  
}

See the sample code Blink without delay, that comes with IDE. If you want to deal with several LED's a library like Timer will be helpful.

The blink-without-delay sketch has a state variable which is very simple. The LED is either on or off. For your system, you must record a lot more information in your internal state:

  1. Which patttern you are currently in
  2. Where you are up to in that pattern
  3. Which LEDs are currently on and off
  4. How long to wait until the next LED must change