Function for multiple blinking led

The problem with the original post is that the 3 variables - state, ledON, ledOFF - need to be in an array. The way you have it, each of the 3 pins are using the same variables, and it's messing things up. I put together a corrected version, and even tried it, so I know it works :slight_smile:

long time = 0;
long timeON[14];    // I assume your pins go from 0-13
long timeOFF[14];
int state[14];

void setup()
{
 int i;
 for(i=0;i<=13;i++) {          //Edit: changed 14 to 13
   timeON[i] = 0;
   timeOFF[i] = 0;
   state[i] = LOW;
 }
 Serial.begin(38400);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
}

void loop()
{
 flashled(10, 1000, 500);
 flashled(11, 500, 1000);
 flashled(12, 500, 500);
}

void flashled(int ledpin, int ledON, int ledOFF) {
 time = millis();
 if (state[ledpin] == HIGH) {
   if (time >= timeOFF[ledpin]) { 
     state[ledpin] = LOW;
     //Serial.print(ledpin);Serial.print(" ");Serial.println(state[ledpin]);
     digitalWrite(ledpin, state[ledpin]);
     timeON[ledpin] = timeOFF[ledpin] + ledOFF;
   }
 }
 else {
   if (state[ledpin] == LOW){
     if (time >= timeON[ledpin]) {
       timeON[ledpin] = millis();      // you don't really need this line
       state[ledpin] = HIGH;
       //Serial.print(ledpin);Serial.print(" ");Serial.println(state[ledpin]);
       digitalWrite(ledpin, state[ledpin]);
       timeOFF[ledpin] = timeON[ledpin] + ledON;
     }
   }
 }
}

Good luck!