LED "on" whilst the other flashes then reverse?

Hi,

I’m "extremely" new to all this and thought I was doing well as first attempt at making an LED flash to a pattern of - 5 seconds ON then flash 5 times every 1 second then loop again - worked first time (I know that probably amazingly simple to most)!

However, now I'm stumped..... how do I make the LED on Pin 13 stay on whilst the LED on pin 7 does the same flash pattern as what pin 13 just ran through and then after pin 7 has done its thing loop back to pin 13 to flash in the same sequence and so on......?

I am using an Arduino Uno R3.

Help much appreciated.
:slight_smile:

Hi....

You could use another loop inside the main loop()- check the Reference on Control Structures.

Something along the lines of (not code, but just the idea)

Main loop
    do your thing with pin 13
        inner loop
            do your thing with pin 7
        end inner loop
end main loop

:astonished:

Thanks for the reply.

Do you know of any sample codes that can visually show me how to setup an inner loop?

Here's some food for thought...

The "main" loop (ie the one you have to have, void loop() ) contains three nested loops which in this case I've set up with "for".

// a nest of loops

// need some counters first

int innerCount;
int middleCount;
int outerCount;

void setup(){
}

void loop(){
// void loop containe 3 "for" loops
//the outer loop contains the other two
//outer loop goes 10 times
//    middle loop goes 5 times each time the outer loop goes
//         inner loop goes 3 times each time the middle one goes

for (outerCount=0; outerCount <= 10; outerCount++){
      // do some stuff and have the middle loop in here
        for (middleCount=0; middleCount <= 5; middleCount++){
        // do some stuff and have the inner loop in here
           for (innerCount=0; innerCount <= 3; innerCount++){
           // do some stuff and have the inner loop in here
      
   } // end of inner   
   } // end of middle 
   } // end of outer ... note the loops end in the reverse sequence to how they started
   
} //end of main loop

But I'd urge you to read up on Control Structures....

However, now I'm stumped..... how do I make the LED on Pin 13 stay on whilst the LED on pin 7 does the same flash pattern as what pin 13 just ran through and then after pin 7 has done its thing loop back to pin 13 to flash in the same sequence and so on......?

This is really suited to a subroutine where you pass the pin number of the LED you want to control. Call it first time with pin 13 then again with pin 7

void setup() {
    // put your setup code here, to run once:
    pinMode(7, OUTPUT);     
    pinMode(13, OUTPUT);     
}

void loop() {
    // put your main code here, to run repeatedly: 
    flashLED(13);
    flashLED(7);
}

void flashLED(int pinNumber){
    digitalWrite(pinNumber,HIGH);
    delay(100);
    digitalWrite(pinNumber,LOW);
}