Syncing LEDs With Piezo Buzzer

Hey there! I'm using a combination of CIRC-02 and CIRC-06

I'd like to sync up LEDs to certain notes of my poor man's 7 nation army. For example: when an e note is played, flash all odd pins (1,3,5,7). I'm using 8 LEDs for pins 1-9 with the Piezo buzzer on pin 10.

Should I use an if statement?

int speakerPin = 10;
char names[] = {'c','d','e','f','g','a','b','C','D','E','F','G','A','B'};
int rangeOfNotes = 14; 
int tones[] ={1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 850, 760, 716, 638, 568, 507};
int length = 7; 
char notes[] = "eegedcc ";
double beats[] = {7, 2, 3, 3, 3, 8, 8,};
int tempo = 120; 

void setup(){
  
 pinMode(speakerPin, OUTPUT);
 }

void loop(){
 delay(240);
 for (int i = 0; i < length; i++){
 if (notes[i] == ' '){
 delay(beats[i] * tempo); 
 } 
 else { 
 playNote(notes[i], beats[i] * tempo);
 }
 }
 }

void playNote(char note, int duration){
 for (int i = 0; i < rangeOfNotes; i++){
 if (names[i] == note){
 playTone(tones[i], duration);
 }
 }
 }

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

Thanks!!!

your playTone() function will lockup the processor for the duration of the tone. So you won't be able to blink anything during that time

if you were to use the tone() function then you can use it in a non blocking way and perform your LED animation whilst playing the notes.