user39315: First of all, I'm new so please don't think this is dumb. I am creating a light culture with RGB LEDs that should play to programmed music. I have uploaded the following code to a spark fun redbird for now, but will later put it on a arduino mega. My circuit is working fine mostly except for the fact that the lights and music play separately and not next to each other. Note: this is just trial code, I will put my own music and light sequencing in later.
const int buzzerPin = 6;    // connect the buzzer to pin 6
const int RED_PIN = 11;
const int GREEN_PIN = 12;
const int BLUE_PIN = 13;
const int RED_PIN2 = 8;
const int GREEN_PIN2 = 9;
const int BLUE_PIN2 = 10;
const int songLength = 18;  // sets the number of notes of the song

const int DISPLAY_TIME = 100; 
// Notes is an array of text characters corresponding to the notes
// in your song. A space represents a rest (no tone)

char notes[songLength] = {
  'c', 'd', 'f', 'd', 'a', ' ', 'a', 'g', ' ', 'c', 'd', 'f', 'd', 'g', ' ', 'g', 'f', ' '}; 

// beats[] is an array of values for each note. A "1" represents a quarter-note, 
// "2" a half-note, and "4" a quarter-note.
// Don't forget that the rests (spaces) need a length as well.

int beats[songLength] = {
  1, 1, 1, 1, 1, 1, 4, 4, 2, 1, 1, 1, 1, 1, 1, 4, 4, 2};

int tempo = 113;  // The tempo is how fast to play the song (beats per second).

void setup() 
{
  pinMode(buzzerPin, OUTPUT);  // sets the  buzzer pin as an OUTPUT
   pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
   pinMode(RED_PIN2, OUTPUT);
  pinMode(GREEN_PIN2, OUTPUT);
  pinMode(BLUE_PIN2, OUTPUT);
}


void loop() 
{
  mainColors();        // Red, Green, Blue, Yellow, Cyan, Purple, White
  int i, duration; //

  for (i = 0; i < songLength; i++) // for loop is used to index through the arrays
  {
    duration = beats[i] * tempo;  // length of note/rest in ms

    if (notes[i] == ' ')          // is this a rest? 
      delay(duration);            // then pause for a moment
    else                          // otherwise, play the note
    {
      tone(buzzerPin, frequency(notes[i]), duration);
      delay(duration);            // wait for tone to finish
    }
    delay(tempo/10);              // brief pause between notes
  }


  // We only want to play the song once, so we pause forever
  }
  // If you'd like your song to play over and over, remove the while(true)
  // statement above


int frequency(char note) 
{
  int i;
  const int numNotes = 8;  // number of notes we're storing
  char names[numNotes] = { 
    'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'    };
  int frequencies[numNotes] = {
    262, 294, 330, 349, 392, 440, 494, 523    };

  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.

  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency and exit function.
    }
  }
  return(0);  // We looked through everything and didn't find it,
  // but we still need to return a value, so return 0.
}

void mainColors()
{
  // Red
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
   digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Green
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Blue
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
   digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Yellow (Red and Green)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);

  // Cyan (Green and Blue)
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Purple (Red and Blue)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);

  // White (turn all the LEDs on)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);
}


user-1: You need a state machine. It goes like this:
You divide your actions in states. Each state is a collection of actions that must performed in group (sequentially). In your case, you have one state for each note and for each ligth color and a duration.
Now, your score (music + light) is made of a sequence of states:
> state 1: Play Fa, Light up RED - Duration 500ms. 
> state 2: Play Re, Light down RED - Duration 200ms. ...
> 
> state n: Play Fa, Light up BLUE - Duration 250 ms.

You have many states; put them in an array and then loop across the array.
The code looks like this:
typedef struct {
    int note;  // Musical note
    int color; // Led color
    int length; // Duration in ms
} STATE;

STATE score[] = {
    {0, 0, 0},
    {FA, BLUE, 500},
    [RE, RED, 400},
    ...
   {FA, GREEN, 400}
   };

int state = 0;

void loop()
{
    static unsigned long stateStart = 0;

    if(state == sizeof(score) / sizeof(STATE)) {
        //  reset and start again
        state = 0;
        stateStart = 0;
    }

    if(millis() - stateStart >= score[state].time) {
        // Advance state and play next thing
        state++;
        playNote(score[state].note, duration);
        playColor(score[state].color);
        stateStart = millis();
    }

}

void playNote(int note, duration)
{
    // Play a note.
}

void playColor(int color)
{
    // Light up a color.
}

Note: this is just the general idea. You must adapt and adjust things, like how you code note and colors. You better Google "Arduino state machine".
My code probably contains errors, but I gave you a starting point.
You have to implement playNote and playColor. 

39315: <p>First of all, I'm new so please don't think this is dumb. I am creating a light culture with RGB LEDs that should play to programmed music. I have uploaded the following code to a spark fun redbird for now, but will later put it on a arduino mega. My circuit is working fine mostly except for the fact that the lights and music play separately and not next to each other. Note: this is just trial code, I will put my own music and light sequencing in later.</p>

<pre><code>const int buzzerPin = 6;    // connect the buzzer to pin 6
const int RED_PIN = 11;
const int GREEN_PIN = 12;
const int BLUE_PIN = 13;
const int RED_PIN2 = 8;
const int GREEN_PIN2 = 9;
const int BLUE_PIN2 = 10;
const int songLength = 18;  // sets the number of notes of the song

const int DISPLAY_TIME = 100; 
// Notes is an array of text characters corresponding to the notes
// in your song. A space represents a rest (no tone)

char notes[songLength] = {
  'c', 'd', 'f', 'd', 'a', ' ', 'a', 'g', ' ', 'c', 'd', 'f', 'd', 'g', ' ', 'g', 'f', ' '}; 

// beats[] is an array of values for each note. A "1" represents a quarter-note, 
// "2" a half-note, and "4" a quarter-note.
// Don't forget that the rests (spaces) need a length as well.

int beats[songLength] = {
  1, 1, 1, 1, 1, 1, 4, 4, 2, 1, 1, 1, 1, 1, 1, 4, 4, 2};

int tempo = 113;  // The tempo is how fast to play the song (beats per second).

void setup() 
{
  pinMode(buzzerPin, OUTPUT);  // sets the  buzzer pin as an OUTPUT
   pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
   pinMode(RED_PIN2, OUTPUT);
  pinMode(GREEN_PIN2, OUTPUT);
  pinMode(BLUE_PIN2, OUTPUT);
}


void loop() 
{
  mainColors();        // Red, Green, Blue, Yellow, Cyan, Purple, White
  int i, duration; //

  for (i = 0; i &lt; songLength; i++) // for loop is used to index through the arrays
  {
    duration = beats[i] * tempo;  // length of note/rest in ms

    if (notes[i] == ' ')          // is this a rest? 
      delay(duration);            // then pause for a moment
    else                          // otherwise, play the note
    {
      tone(buzzerPin, frequency(notes[i]), duration);
      delay(duration);            // wait for tone to finish
    }
    delay(tempo/10);              // brief pause between notes
  }


  // We only want to play the song once, so we pause forever
  }
  // If you'd like your song to play over and over, remove the while(true)
  // statement above


int frequency(char note) 
{
  int i;
  const int numNotes = 8;  // number of notes we're storing
  char names[numNotes] = { 
    'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'    };
  int frequencies[numNotes] = {
    262, 294, 330, 349, 392, 440, 494, 523    };

  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.

  for (i = 0; i &lt; numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency and exit function.
    }
  }
  return(0);  // We looked through everything and didn't find it,
  // but we still need to return a value, so return 0.
}

void mainColors()
{
  // Red
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);
   digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Green
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Blue
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
   digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Yellow (Red and Green)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);

  // Cyan (Green and Blue)
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, HIGH);
  delay(DISPLAY_TIME);

  // Purple (Red and Blue)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, LOW);
  digitalWrite(GREEN_PIN2, HIGH);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);

  // White (turn all the LEDs on)
  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);
    digitalWrite(RED_PIN2, HIGH);
  digitalWrite(GREEN_PIN2, LOW);
  digitalWrite(BLUE_PIN2, LOW);
  delay(DISPLAY_TIME);
}
</code></pre>
 -1: <p>You need a <em>state machine</em>. It goes like this:</p>

<p>You divide your actions in states. Each state is a collection of actions that must performed in group (sequentially). In your case, you have one state for each note and for each ligth color and a duration.</p>

<p>Now, your score (music + light) is made of a sequence of states:</p>

<pre><code>&gt; state 1: Play Fa, Light up RED - Duration 500ms. 
&gt; state 2: Play Re, Light down RED - Duration 200ms. ...
&gt; 
&gt; state n: Play Fa, Light up BLUE - Duration 250 ms.
</code></pre>

<p>You have many states; put them in an array and then loop across the array.</p>

<p>The code looks like this:</p>

<pre><code>typedef struct {
    int note;  // Musical note
    int color; // Led color
    int length; // Duration in ms
} STATE;

STATE score[] = {
    {0, 0, 0},
    {FA, BLUE, 500},
    [RE, RED, 400},
    ...
   {FA, GREEN, 400}
   };

int state = 0;

void loop()
{
    static unsigned long stateStart = 0;

    if(state == sizeof(score) / sizeof(STATE)) {
        //  reset and start again
        state = 0;
        stateStart = 0;
    }

    if(millis() - stateStart &gt;= score[state].time) {
        // Advance state and play next thing
        state++;
        playNote(score[state].note, duration);
        playColor(score[state].color);
        stateStart = millis();
    }

}

void playNote(int note, duration)
{
    // Play a note.
}

void playColor(int color)
{
    // Light up a color.
}
</code></pre>

<p>Note: this is just the general idea. You must adapt and adjust things, like how you code note and colors. You better Google "Arduino state machine".</p>

<p>My code probably contains errors, but I gave you a starting point.</p>

<p>You have to implement playNote and playColor. </p>
