same code run two times one after other

Hi everybody,

I have a code but I want to run the code two or three times but first time for given time on pin 12 after finish, same code start for pin 11 for given time and so on....pls help me out for this... thanks

int led = 11; bool ledOn; int led1 = 12; bool ledOn1;

void setup() {

pinMode(led, OUTPUT); // initialize the digital pin as an output. digitalWrite(led, HIGH); // turn led on ledOn = true; // led is on

pinMode(led1, OUTPUT); // initialize the digital pin as an output. digitalWrite(led1, HIGH); // turn led on ledOn1 = true; // led is on }

void loop() { if (ledOn) { delay(5000); digitalWrite(led, LOW); // turn led off ledOn = false; // prevent this code being run more then once

} } // Other loop code here . . .

void loop1() { if (ledOn1) { delay(5000); digitalWrite(led1, LOW); // turn led off ledOn1 = false; // prevent this code being run more then once

} }

bool Tick = true;

void loop() {

if( Tick ) {
  if (ledOn) {
    delay(5000);
    digitalWrite(led, LOW); // turn led off
    ledOn = false;  // prevent this code being run more then once
   Tick = false;
  }
} else {

  if (ledOn1) {
    delay(5000);
    digitalWrite(led1, LOW); // turn led off
    ledOn1 = false;  // prevent this code being run more then once
Tick=true;
  
  }
}
}

Something like that.

Thanx Idahowalker,

I wrote the code as per u…but there are a problem…LED (pin 12) and LED2(pin11) ON same time after 5 second LED(pin12) off and LED1(pin 11) still on till 10 second and then goes OFF.

but I want LED(pin12) ON for 5 second after 5 second this should OFF permanent then LED1( pin11) should ON for 5 second and then OFF permanent.

Thnx

int led = 12;
int led1 = 11;
bool ledOn;
bool ledOn1;
void setup() {

pinMode(led, OUTPUT); // initialize the digital pin as an output.
digitalWrite(led, HIGH); // turn led on
ledOn = true; // led is on

pinMode(led1, OUTPUT); // initialize the digital pin as an output.
digitalWrite(led1, HIGH); // turn led on
ledOn1 = true; // led is on

}

bool Tick = true;

void loop() {

if( Tick ) {
if (ledOn) {
delay(5000);
digitalWrite(led, LOW); // turn led off
ledOn = false; // prevent this code being run more then once
Tick = false;
}
} else {

if (ledOn1) {
delay(5000);
digitalWrite(led1, LOW); // turn led off
ledOn1 = false; // prevent this code being run more then once
Tick=true;

}
}
}

First, learn to use millis() and not delay() to blink an LED.