LED's blinking in different time intervals at same time?

I am trying to blink two different messages in morse code at the same time.

I used delay in my code, which evidently will not work and milliseconds are too far over my head.

If someone more experienced could shed light on how to display my messages at the same time, it would be much appreciated.

void setup() {
 
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop() {

  digitalWrite(13, HIGH); 
  delay(250);
  digitalWrite(13, LOW); 
  delay(250);
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW); 
  delay(250);
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW); 
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);  //G
  delay(500);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);                  //H
  delay(500);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW); 
  delay(500);                             //E
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);              //R
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);             //E
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);             //E
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(500);                              //L
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(500);            //T
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);           //I
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW); 
  delay(500);                              //L
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);           //N
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(750);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);                    //O
  delay(1000);                              //HELLO
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(500);           //G
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);                       //W
  delay(500); 
  digitalWrite(12, HIGH);
  delay(250);
  digitalWrite(12, LOW);
  delay(1000);         //S GREETINGS
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);                        //O
  delay(500);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);                        //R
  delay(500);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);                        //L
  delay(500);
  digitalWrite(13, HIGH);
  delay(750);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);
  delay(250);
  digitalWrite(13, HIGH);
  delay(250);
  digitalWrite(13, LOW);                        //D
  delay(1000);                              //WORLD
  
  
  
}

There is no hope if millis is over your head. There is no simpler way. You'd be asking about more complex ways to an easy problem.

Study the blink without delay example, it has all the answers.

INTP:
Study the blink without delay example, it has all the answers.

I would not say that. Blink without delay demonstrates just one of several techniques you will need to master to achieve what you want. For example you will also need to learn how to generate timing sequences by representing them as data structures rather than program structures, and write code to interpret and action that sequence data.

But there is a simple solution that will allow you to achieve what you want with the skills you already have. It is wasteful of resources, but you must weigh that against your time and effort. Use two Arduinos.

Another idea, requiring only one Arduino, is simple enough but would make life hard if you ever want to change the messages. On a sheet of graph paper or squared paper, draw two parallel time-lines. Write each Morse message along one of the time lines, accurately marking where each dot and dash starts and ends. Then, working left to right along both lines together, turn both sequences into a single sequence of on and off events, and the time gaps between them. You can code that into a series of digitalWrite() and delay() commands.

It's just morse code. Pick a long interval, pick a short interval, and the rest is just copy/paste sequencing.
Probably could write up a character table but this kind of thing has probably already been done.

PaulRB:
Another idea, requiring only one Arduino, is simple enough but would make life hard if you ever want to change the messages. On a sheet of graph paper or squared paper, draw two parallel time-lines. Write each Morse message along one of the time lines, accurately marking where each dot and dash starts and ends. Then, working left to right along both lines together, turn both sequences into a single sequence of on and off events, and the time gaps between them. You can code that into a series of digitalWrite() and delay() commands.

What would I write on each line exactly? And could one LED display “Hello World” and the other one “Goodbye”

Mertalics44323:
What would I write on each line exactly?

Each line of code would be either switching a led on or switching a led off or a delay. Nothing you haven't already used.

Mertalics44323:
And could one LED display "Hello World" and the other one "Goodbye"

Yes, is up to you. One disadvantage of this simple technique is that the shorter of the two messages cannot start again until the longer one has finished.

PaulRB:
Each line of code would be either switching a led on or switching a led off or a delay. Nothing you haven't already used.

Sorry, still a little confused. Can you give a short excerpt of what it would look like? Also, how would I combine the words on a timeline?

Okay let's ignore the easy solution to ask 100 questions about a convoluted rigid method that is flawed.

What he's probably saying is to consider that your two LEDs can exist in 4 states. Both off, either on, both on.
You have to manually script out your two messages on a timeline (literally pen and paper) and imagine what the leds would be doing at every single point in time.

Your messages need to be predetermined and you will have to redo this whole mess for any changes.
You need to figure out exact duration of shorts and longs. You'll have to keep them at a nice fraction of each other to keep the math from overwhelming you. The juxtaposition is messy unless you don't care about sloppy morse code with sporadic pauses.

Mertalics44323:
Can you give a short excerpt of what it would look like?

OK, "Hello" starts with an H which is "....". "Goodbye" starts with a G which is "--."

Lets assume a dot is 250ms, a dash is 750 ms and the gap between dots & dashes is 250ms.

digitalWrite(LED1, HIGH); // Start the first dot of "H"
digitalWrite(LED2, HIGH); // Start the first dash of "G"
delay(250);
digitalWrite(LED1, LOW); // End the first dot of "H"
delay(250);
digitalWrite(LED1, HIGH); // Start the second dot of "H"
delay(250);
digitalWrite(LED1, LOW); // End the second dot of "H"
digitalWrite(LED2, HIGH); // End the first dash of "G"
delay(250);
digitalWrite(LED1, HIGH); // Start the third dot of "H"
digitalWrite(LED2, HIGH); // Start the second dash of "G"
delay(250);

... and so on.

As INTP says, this is simple but laborious, and if you want to change the messages, you have to start over. But it is simple. When you are ready to take your programming skills to the next level, there are much better ways to do this.

You may try this sketch.

overflow_test.ino (729 Bytes)