I have technical problem with music shield

To. Seeed Studio.
Hi. We are Yongsu arduino club.
This time, We are making stairs piano with your music shield midi function.
but we meet some technical problem with music shield
This is our code(We’ll use ultrasound censor)
what is wrong? Please tell us wrong part and how to fix it
Thank you.

#include <SD.h>
#include <SPI.h>
#include <Arduino.h>
#include <MusicPlayer.h>

int trig_low_b = 22;
int trig_c = 24;
int trig_d = 26;
int trig_e = 28;
int trig_f = 30;
int trig_g = 32;
int trig_a = 34;
int trig_b = 36;
int trig_high_c = 38;
int trig_high_d = 40;
int echo_low_b = 23;
int echo_c = 25;
int echo_d = 27;
int echo_e = 29;
int echo_f = 31;
int echo_g = 33;
int echo_a = 35;
int echo_b = 37;
int echo_high_c = 39;
int echo_high_d = 41;

long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

long distance(int trig, int echo)
{
long duration, cm;
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
duration = pulseIn(echo,HIGH);
cm = microsecondsToCentimeters(duration);
return(cm);
}

void setup() {
pinMode(trig_low_b, OUTPUT);
pinMode(trig_c, OUTPUT);
pinMode(trig_d, OUTPUT);
pinMode(trig_e, OUTPUT);
pinMode(trig_f, OUTPUT);
pinMode(trig_g, OUTPUT);
pinMode(trig_a, OUTPUT);
pinMode(trig_b, OUTPUT);
pinMode(trig_high_c, OUTPUT);
pinMode(trig_high_d, OUTPUT);
pinMode(echo_low_b, OUTPUT);
pinMode(echo_c, OUTPUT);
pinMode(echo_d, OUTPUT);
pinMode(echo_e, OUTPUT);
pinMode(echo_f, OUTPUT);
pinMode(echo_g, OUTPUT);
pinMode(echo_a, OUTPUT);
pinMode(echo_b, OUTPUT);
pinMode(echo_high_c, OUTPUT);
pinMode(echo_high_d, OUTPUT);
Serial.begin(9600);
player.beginInMidiFmt();
}

void loop() {
long low_b_distance = distance(trig_low_b, echo_low_b);
long c_distance = distance(trig_c, echo_c);
long d_distance = distance(trig_d, echo_d);
long e_distance = distance(trig_e, echo_e);
long f_distance = distance(trig_f, echo_f);
long g_distance = distance(trig_g, echo_g);
long a_distance = distance(trig_a, trig_a);
long b_distance = distance(trig_b, echo_b);
long high_c_distance = distance(trig_high_c, echo_high_c);
long high_d_distance = distance(trig_high_d, echo_high_d);

if(low_b_distance < 170)
{
player.midiNoteOn(1, 59, 100);
delay(500);
player.midiNoteOff(1, 59, 100);
delay(500);
}
if(c_distance < 170)
{
player.midiNoteOn(1, 60, 100);
delay(500);
player.midiNoteOff(1, 60, 100);
delay(500);
if(c_distance<170)
{
delay(700);
if(g_distance<170)
{
delay(700);
if(g_distance<170)
{
delay(700);
if(a_distance<170)
{
delay(700);
player.midiNoteOn(1, 69, 100);
delay(500);
player.midiNoteOff(1, 69, 100);
delay(500);
player.midiNoteOn(1, 67, 100);
delay(500);
player.midiNoteOff(1, 67, 100);
delay(1000);
player.midiNoteOn(1, 65, 100);
delay(500);
player.midiNoteOff(1, 65, 100);
delay(500);
player.midiNoteOn(1, 65, 100);
delay(500);
player.midiNoteOff(1, 65, 100);
delay(500);
player.midiNoteOn(1, 64, 100);
delay(500);
player.midiNoteOff(1, 64, 100);
delay(500);
player.midiNoteOn(1, 64, 100);
delay(500);
player.midiNoteOff(1, 64, 100);
delay(500);
player.midiNoteOn(1, 62, 100);
delay(500);
player.midiNoteOff(1, 62, 100);
delay(500);
player.midiNoteOn(1, 62, 100);
delay(500);
player.midiNoteOff(1, 62, 100);
delay(500);
player.midiNoteOn(1, 60, 100);
delay(500);
player.midiNoteOff(1, 60, 100);
delay(500);
}
}
}
}
}
if(d_distance < 170)
{
player.midiNoteOn(1, 62, 100);
delay(500);
player.midiNoteoff(1, 62, 100);
delay(500);
}
if(e_distance < 170)
{
player.midiNoteOn(1, 64, 100);
delay(500);
player.midiNoteOff(1, 64, 100);
delay(500);
}
if(f_distance < 170)
{
player.midiNoteOn(1, 65, 100);
delay(500);
player.midiNoteOff(1, 65, 100);
delay(500);
}
if(g_distance < 170)
{
player.midiNoteOn(1, 67, 100);
delay(500);
player.midiNoteOff(1, 67, 100);
delay(500);
}
if(a_distance < 170)
{
player.midiNoteOn(1, 69, 100);
delay(500);
player.midiNoteOff(1, 69, 100);
delay(500);
}
if(b_distance < 170)
{
player.midiNoteOn(1, 71, 100);
delay(500);
player.midiNoteOff(1, 71, 100);
delay(500);
}
if(high_c_distance < 170)
{
player.midiNoteOn(1, 72, 100);
delay(500);
player.midiNoteOff(1, 72, 100);
delay(500);
}
if(high_d_distance < 170)
{
player.midiNoteOn(1, 74, 100);
delay(500);
player.midiNoteOff(1, 74, 100);
delay(500);
}
}

Hello,

I do not know much information about your own project so can not give your more advice. Could you pls run demo MIDI player to make sure your hardware is all right. And I’ve seen you are calling the function player.midiNoteOff( ) as well as player.midiNoteOn( ), they are all private objects, pls modify them into public befor calling.


Thanks
best rgds
Mancy

Hello,
our project is installing piano at our school stairs. if people tread stairs, ultrasound sensor react and music shield sounds correct sounds for each stairs.
our problem is, arduino ide prints error massage “within this scope”(we fixed code and plz ignore the code below) at midi action code like ‘player.midiNoteOn(1, 76, 100);’ when we compile code.
i think i didnt understand all about this function and parameters. i know that 1 is midi type, 76 is midi note, 100 is midi power, is it true?
if I am wrong, plz tell me what is right.
and we tested midi shield and have no problem with hardware.

Hello,
The meanings of the three parameters of player.midiNoteOn( ) are as follows:
1.channel 2.type 3.note
And I compiled your code, meeting no problem without a case error, pls make sure you have modified the two functions I mentioned into public objects.

Thanks!
best rgds
Mancy