two void loops at the same time (easy)

is there an easy way to have two loops at the same time???
For Example: i have this code:

char mychar;
int notes[] = {262, 349};

void setup(){
  // declare the LED pins as outputs 
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
}

void loop(){
  mychar = 'a';
  //LED LOOP
  if(mychar == 'a'){
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    delay(250);
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    delay(250);}
    
  //Tone Loop  
  if(mychar == 'a'){
  tone(8, notes[0]);
    delay(250);
  tone(8, notes[1]);
    delay(250);
  }
}

now what i want is that the LED loop and teh Tone loop run at the same time.
and is that easy because im quite a noob at arduino XD

thanks in advance

You don’t need two loops for that. You just need to interleave the actions.

The demo sketch in this Thread illustrates the process. http://forum.arduino.cc/index.php?topic=223286.0

You will note that it doesn’t use delay() which just paralyzes the Arduino so it can’t do anything else.

…R

Robin2:
You don't need two loops for that. You just need to interleave the actions.

The demo sketch in this Thread illustrates the process. Demonstration code for several things at the same time - Project Guidance - Arduino Forum

You will note that it doesn't use delay() which just paralyzes the Arduino so it can't do anything else.

...R

Aah, i din't knew it paralized the arduino,.

but i don't quite understand the code.
im just an autistic 14 yo XD
i have alot of programming skills but not with arduino XD

can you please make an example code for me?

if so, thanks alot!

void loop(){
  mychar = 'a';
  //LED LOOP
  if(mychar == 'a'){
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);

    tone(8, notes[0]);


    delay(250);
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);

    tone(8, notes[1]);

    delay(250);}
    }
}

yeah, i had that, but it was like an example.
but still thanks XD

The real trick is to not use "delay()".
Another trick is not to have too many closing braces in your functions.
The compiler doesn't like them.

jkctech:
can you please make an example code for me?

The example code is already in the link I gave you.

...R