A noobie question;

I'm fairly new to C++ and the arduino and I've run into a roadblock. I have written some code that plays a tune but I would like it to play while some LEDs flash. I.e. I'd like it to continue calling functions while void musicPlays(); occurs. I can't figure out how or if this is possible :frowning:

void loop()
{
  musicPlaying();
  oneOnAtATime1();
  oneOnAtATime2();
  oneOnAtATime3();
  allFlash();
  
}

I have written some code

I don't see it...

You need to read and understand the "blink without delay" tutorial.
You perhaps need to turn your problem inside-out.

This is my full code if it helps. I know it's ugly. I have read and fully understand the blink tutorial and don't see how it is relevant.

int ledPins[] = {3,4,5,6,7,8,9,10}; /*this array holds the
                                  pins the LEDs are connected
                                  to (LED #0 = pin 3 etc.) */

int speakerPin = 11; //sets piezo pin to PWM pin 11
int length = 30; // the number of notes: 31
char notes[] = "rfgarfgabtsrbtsrCgabCgabaCEGEG";
int beats[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 4, 2, 6};
int tempo = 200;

                                  
void playTone(int tone, int duration)
{
  for(long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite (speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite (speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration)
{
  char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'r', 's', 't', 'E', 'G'};
  int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 1073, 1205, 1355, 758, 638 };
  //play the tone corresponding to the note name
  for (int i = 0; i < 14; i++)
  {
    if(names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}

  void musicPlaying(){
  for(int i = 0; i < length; i++)
  {
    if(notes[i] == ' ')
    {
      delay(beats[i] * tempo); //rest
    }
    else
    {
      playNote(notes[i], beats[i] * tempo);
    }
    //pause between notes
    delay(tempo/2);
  }}


void oneOnAtATime1()

{
  int delayTime = 500; //time to pause (ms) between LEDs)
  for(int j = 0; j <=7; j++)
  {
    int offLED = j - 1; //this calculates the previously on LED
    if(j == 0)
    {
      offLED = 7;
    }
    
    digitalWrite(ledPins[j], HIGH); //turn on LED i
    digitalWrite(ledPins[offLED], LOW);
    delay(delayTime);
  }
}

void oneOnAtATime2()
{
  int delayTime = 400; //time to pause (ms) between LEDs)
  for(int j = 0; j <=7; j++) //i is increased by 1 until it is <= 7
  {
    int offLED = j - 1; //this calculates the previously on LED
    if(j == 0)
    {
      offLED = 7;
    }
    
    digitalWrite(ledPins[j], HIGH); //turn on LED i
    digitalWrite(ledPins[offLED], LOW);
    delay(delayTime);
  }
}

void oneOnAtATime3()
{
  int delayTime = 300; //time to pause (ms) between LEDs)
  for(int j = 0; j <=7; j++) //i is increased by 1 until it is <= 7
  {
    int offLED = j - 1; //this calculates the previously on LED
    if(j == 0)
    {
      offLED = 7;
    }
    
    digitalWrite(ledPins[j], HIGH); //turn on LED i
    digitalWrite(ledPins[offLED], LOW);
    delay(delayTime);
  }
}

void allFlash()
{
  for(int loopLimit = 0; loopLimit < 5; loopLimit++)
  {
  delay(500);
  digitalWrite(ledPins[0], HIGH);
  digitalWrite(ledPins[1], HIGH);
  digitalWrite(ledPins[2], HIGH);
  digitalWrite(ledPins[3], HIGH);
  digitalWrite(ledPins[4], HIGH);
  digitalWrite(ledPins[5], HIGH);
  digitalWrite(ledPins[6], HIGH);
  digitalWrite(ledPins[7], HIGH);
  delay(500);
  digitalWrite(ledPins[0], LOW);
  digitalWrite(ledPins[1], LOW);
  digitalWrite(ledPins[2], LOW);
  digitalWrite(ledPins[3], LOW);
  digitalWrite(ledPins[4], LOW);
  digitalWrite(ledPins[5], LOW);
  digitalWrite(ledPins[6], LOW);
  digitalWrite(ledPins[7], LOW);
  }
}

                                  
void setup()
{
  pinMode(speakerPin, OUTPUT);
  for(int i = 0; i < 8; i ++)
  {
    pinMode(ledPins[i], OUTPUT); /*this is a shortcut to make all
                                  LEDs "output"*/
  }
}

void loop()
{
  musicPlaying();
  oneOnAtATime1();
  oneOnAtATime2();
  oneOnAtATime3();
  allFlash();
  
}
I have read and fully understand the blink tutorial and don't see how it is relevant

I assume you meant "the blink without delay tutorial".

It's relevant because you'll notice that there are no "delay"s in it, whilst in your code, there are lots.

It's the "delay"s that are preventing your code from appearing to be generating tones at the same time as blinking LEDs, because when the processor is in "delay", it is incapable of running anything else; it's just sitting looping and looking at the clock until the specified delay has completed.

Oops, my mistake. I shall absorb the BlinkWithoutDelay tutorial and see if I can come up with a solution. Thank you :-[

I should say that the "delayMicroseconds" delays should probably not be touched, because they will affect your tones' frequencies, but any "delay" needs to be carefully thought about.

It won't be simple, so take it step by step.
Think of your LED blinking as series of states, with each state lasting a period of time. The periods here are of the order of half-a-second, so there's plenty of time.

Google or search the forum for "state machine".