Different led-patteren on one Arduino (delay)

This code dont work. The leds turn on and off at the same time. Im new to coding and maybe DELAY is not the right way to go. Would apriciate any pointers :slight_smile:

int Led1Pin = 2; // pin that turns on Led 1
int Led2Pin = 4; // pin that turns on Led 2

int Led1time = 1; // how long Led 1 is on
int Led2time = 5; // how long Led 2 is on

int Led1wait = 5; // how long Led 1 is off before turning on again
int Led2wait = 10; // how long Led 2 is off before turning on again

void setup()
{
pinMode(Led1Pin, OUTPUT); // set 2 to an output so we can use it to turn on the Led 1
pinMode(Led2Pin, OUTPUT); // set 4 to an output so we can use it to turn on the Led 2
}

void loop()
{
digitalWrite(Led1Pin, HIGH); // turn on Led 1
digitalWrite(Led2Pin, HIGH); // turn on Led 2

delay(Led1time1000); // multiply by 1000 to translate seconds to milliseconds
delay(Led2time
1000); // multiply by 1000 to translate seconds to milliseconds

digitalWrite(Led1Pin, LOW); // turn off Led 1
digitalWrite(Led2Pin, LOW); // turn off Led 2

delay(Led1wait1000); // multiply by 1000 to translate seconds to milliseconds
delay(Led2wait
1000); // multiply by 1000 to translate seconds to milliseconds
}

Putting two delays one after the other will just produce one delay equal to the total of the two delay times.

If you want to run two things on different timings you're going to need to do it differently. Look at timing using millis e.g. Using millis() for timing. A beginners guide - Introductory Tutorials - Arduino Forum

Steve

Ty - I will try the millies.

For help see my
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
Or Robin2's several things at once
http://forum.arduino.cc/index.php?topic=223286.0

Very well written - even for noobs like me. Thx :slight_smile: