LED Light Sequence -HELP

Getting little confused and Need some assistance

I want to write a code that will make 4 LEDs go in a specific sequence

Eg Sequence

LED1 = PIN 5
LED2 = PIN 6
LED3 = PIN 7
LED4 = PIN 8

LED1 goes on for 500 ms then goes Off
Then LED2 goes ON for 500 ms then goes OFF
Then LED1 goes ON for 500 ms then goes OFF
Then LED2 goes ON for 500 ms then goes OFF
Then LED3 goes ON for 500 ms then goes OFF
Then LED4 goes ON for 500 ms then goes OFF
Then LED3 goes ON for 500 ms then goes OFF
Then LED4 goes ON for 500 ms then goes OFF

Then is starts over again

NoProblem:
Getting little confused and Need some assistance

I want to write a code that will make 4 LEDs go in a specific sequence

Eg Sequence

LED1 goes on for 500 ms then goes Off
Then LED2 goes ON for 500 ms then goes OFF
Then LED1 goes ON for 500 ms then goes OFF
Then LED2 goes ON for 500 ms then goes OFF
Then LED3 goes ON for 500 ms then goes OFF
Then LED4 goes ON for 500 ms then goes OFF
Then LED3 goes ON for 500 ms then goes OFF
Then LED4 goes ON for 500 ms then goes OFF

Then is starts over again

I believe that you need to write a function which takes two parameters: the LED to turn on and, optionally, the time to remain on. So, your loop would read as:

void loop(){
ledON(2, 500);
ledON(1, 500);

and so on

}

...something like that.

Thank you for your replay

Please can you expand of your code a little further, still lost

I know i could use

digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second

but this seem very difficult to time the LED lights

please can someone assist further although i have used a LED as an example its really is to turn of some octocouplers were timing is important

NoProblem:
but this seem very difficult to time the LED lights

Why? What you're asking for is straightforward: to turn on an LED:

digitalWrite(led1, HIGH);

To wait 500 ms:

delay(500);

To turn an LED off, and another LED on:

digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);

Etc...

As I believe that in starting to learn programming it can be very useful to see an implementation of something you've specified I give you this.

In return I expect you to research what you see and asking questions until you understand how it works.

#define ARRAY_SIZEOF(ARRAY)     (sizeof(ARRAY) / sizeof(ARRAY[0]))

const uint8_t   pinLED_1    = 5;
const uint8_t   pinLED_2    = 6;
const uint8_t   pinLED_3    = 7;
const uint8_t   pinLED_4    = 8;

const uint8_t   LED_OFF     = LOW;
const uint8_t   LED_ON      = HIGH;

void toggleLED(uint8_t pin, unsigned long tmsOn)
{
    digitalWrite(pin, LED_ON);
    delay(tmsOn);

    digitalWrite(pin, LED_OFF);
}

void loop()
{
    const uint8_t   pinLEDS[] =
    {
          pinLED_1, pinLED_2, pinLED_1, pinLED_2
        , pinLED_3, pinLED_4, pinLED_3, pinLED_4
    };

    for ( size_t i = 0; i < ARRAY_SIZEOF(pinLEDS); i++ )
    {
        toggleLED(pinLEDS[i], 500UL);
    }
}

void setup()
{
    const uint8_t   pinLEDS[]   = { pinLED_1, pinLED_2, pinLED_3, pinLED_4 };

    for ( size_t i = ARRAY_SIZEOF(pinLEDS); i--; )
    {
        pinMode(pinLEDS[i], OUTPUT);
    }
}