piezo to midi code help wanted !

hey thanks a lot for the fast help !
the first piezo worked out fine indeed ,
now i've hooked up 4 piezos and adapted the code
( added the 3 piezos and changed midi note number )
but i must be wrong somewhere since i get an error message at the end again when compiling/verifying...
( >in function 'void loop()': error a function-definition is not allowed here before '{' token

  • void noteOn(char cmd, char data1,char data2) is highlighted

any suggestions ? stupid things i'm forgetting ? non-stupid things i'm forgetting ?
thanks!

here's the code :

// 4 piezos to midi

int ledPin = 13 ; // Led connected to digital pin 13
int piezo1 = 0 ; // Piezo 1 connected to analog 0
byte val = 0 ; // variable to store the value read from the sensor pin
int piezo2 = 1 ; // Piezo 1 connected to analog 1
byte val2 = 0 ; // variable to store the value read from piezo2pin
int piezo3 = 2 ; // Piezo 3 connected to analog 2
byte val3 = 0 ; // variable to store the value read from piezo3pin
int piezo4 = 3 ; // Piezo 4 connected to analog 3
byte val4 = 0 ; // variable to store the value read from piezo4pin
int statePin = 0; // variable used to store the last LED status , to toglle the light
byte THRESHOLD = 80; // threshold value to decide when the detected sound is a knock or not

void setup()
{
pinMode(ledPin, OUTPUT); // declare the ledPin as OUTPUT
Serial.begin(31250); // set MIDI baud rate
}

void loop(){
// deal with first piezo
val = analogRead(piezo1)/4;
if (val >= THRESHOLD) {
noteOn (144 , 10, 100);
delay(180);
noteOn (144 , 10, 0);
digitalWrite(ledPin, HIGH);
delay(100);

// deal with second piezo
val2 = analogRead(piezo2)/4;
if (val2 >= THRESHOLD) {
noteOn (144 , 12, 100);
delay(180);
noteOn (144 , 12, 0);
digitalWrite(ledPin, HIGH);
delay(100);

// deal with third piezo
val3 = analogRead(piezo3)/4;
if (val3 >= THRESHOLD) {
noteOn (144 , 14, 100);
delay(180);
noteOn (144 , 14, 0);
digitalWrite(ledPin, HIGH);
delay(100);

// deal with fourt piezo
val4 = analogRead(piezo4)/4;
if (val4 >= THRESHOLD) {
noteOn (144 , 16, 100);
delay(180);
noteOn (144 , 16, 0);
digitalWrite(ledPin, HIGH);
delay(100);
}
}

// plays a MIDInote doesn't check to see that cmd is greater than 127 or that data values are less than 127
void noteOn(char cmd, char data1,char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}