This should do what you wanted:
const int speakerPin = 10;
const int length = 15; // the number of notes
const char notes[] = "ccggaagffeeddc "; // a space represents a rest
const int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
const int tempo = 300;
const int led1 = 0;
const int led2 = 1;
const int led3 = 2;
const int led4 = 3;
const int led5 = 4;
const int led6 = 5;
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
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);
}
}
const char names[] = "cdefgabC";
const int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
void playNote(char note, int duration) {
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
digitalWrite(led1, note == 'c');
digitalWrite(led2, note == 'g');
digitalWrite(led3, note == 'a');
digitalWrite(led4, note == 'f');
digitalWrite(led5, note == 'e');
digitalWrite(led6, note == 'd');
playTone(tones[i], duration);
break; // No need to look at the rest of the names
}
}
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}
delay(tempo / 2);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
delay(1000); // pause between repeats
}