Bonjour à tous,
je suis nouveau dans l'univers de l'arduino et et l'électronique en général. Je me sers de ce projet (normalement basique) pour essayer de comprendre un peu mieux ce qui s'y passe.
Je suis en train de convertir un vieux pédalier d'orgue des 70's en contrôleur MIDI en passant par un arduino mega 2560. Il parait que ce n'est pas le top pour le midi mais c'est tout ce que vendait pour petit revendeur local.
La partie hardware du projet est terminée et semble fonctionner. J'ai relié chacune des 13 notes de mon orgue aux digital pins 22 à 34, toutes reliées à un même GND.
Le 2560 n'étant pas compatible MIDI over USB, j'utilise une fiche midi 5 pin pour le midi out et c'est là que ça se corse. L'arduino reçoit un signal midi quand j'actionne le pédale (la led RX clignote quand j'appuie et quand je relache) mais pas moyen de récupérer ce signal par la fiche 5 pin.
Voici le code que j'ai utilisé (auquel je ne comprends pas grand chose, mais ça vient doucement). Il est calqué sur le tuto youtube de LOOK MUM NO COMPUTER et adapté à mes besoins. Il utilise un UNO, c'est sans doute de là que vient le problème. Il y a aussi des petites blagues anglophiles que je n'ai pas effacées (comme buttonbeans pour buttonvalues).
Qu'est-ce que j'ai raté ?
//below is a code with slightly more complexity to only send midi on and off commands once for every button push
// this is quoting the code from the video https://youtu.be/wY1SRehZ9hM
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int button1 = 22; //button1 on digital pin 22
int button2 = 23; //button2 on digital pin 23
int button3 = 24; //button3 on digital pin 24
int button4 = 25; //button4 on digital pin 25
int button5 = 26; //button5 on digital pin 26
int button6 = 27; //button6 on digital pin 27
int button7 = 28; //button7 on digital pin 28
int button8 = 29; //button8 on digital pin 29
int button9 = 30; //button9 on digital pin 30
int button10 = 31; //button10 on digital pin 31
int button11 = 32; //button11 on digital pin 32
int button12 = 33; //button12 on digital pin 33
int button13 = 34; //button13 on digital pin 34
int button1beans = 0;
int button2beans = 0;
int button3beans = 0;
int button4beans = 0;
int button5beans = 0;
int button6beans = 0;
int button7beans = 0;
int button8beans = 0;
int button9beans = 0;
int button10beans = 0;
int button11beans = 0;
int button12beans = 0;
int button13beans = 0;
int button1state = 0; //these state values help us only sendmidi commands once for every button put
int button2state = 0; //bear in mind this will only be a problem if you plan on having lots of midi things going on at once
int button3state = 0; //it just stops clogging up the midi feed with constant midi off commands.
int button4state = 0; //as themore keys you send the more midi off commands are constantly being sent
int button5state = 0; //so this just neatens the midi stream a bit to prevent mistakes.
int button6state = 0;
int button7state = 0;
int button8state = 0;
int button9state = 0;
int button10state = 0;
int button11state = 0;
int button12state = 0;
int button13state = 0;
void setup()
{
MIDI.begin(); //BEINNINFG IDIU TGHUBGS
pinMode(button1, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button2, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button3, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button4, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button5, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button6, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button7, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button8, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button9, INPUT_PULLUP); //pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button10, INPUT_PULLUP);//pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button11, INPUT_PULLUP);//pinMode means the pin is in input mode with an internal pull up resistor, so it is waiting to receive ground to do something
pinMode(button12, INPUT_PULLUP);
pinMode(button13, INPUT_PULLUP);
}
void loop()
{
button1beans = digitalRead(button1); //read status of button
button2beans = digitalRead(button2); //read status of button
button3beans = digitalRead(button3); //read status of button
button4beans = digitalRead(button4); //read status of button
button5beans = digitalRead(button5); //read status of button
button6beans = digitalRead(button6); //read status of button
button7beans = digitalRead(button7); //read status of button
button8beans = digitalRead(button8); //read status of button
button9beans = digitalRead(button9); //read status of button
button10beans = digitalRead(button10); //read status of button
button11beans = digitalRead(button11); //read status of button
button12beans = digitalRead(button12);
button13beans = digitalRead(button13);
if ((button1beans == LOW) && (button1state == 0))
{ MIDI.sendNoteOn(24,127,1); //turn midi note on 24 velocity 127, midi channel 1.
button1state = 1;}
if ((button1beans == HIGH) && (button1state == 1))
{ MIDI.sendNoteOff(24,0,1); //turn midi note off 24 velocity 127, midi channel 1.
button1state = 0;
}
if ((button2beans == LOW) && (button2state == 0))
{ MIDI.sendNoteOn(25,127,1); //turn midi note on 25 velocity 127, midi channel 1.
button2state = 1;}
if ((button2beans == HIGH) && (button2state == 1))
{ MIDI.sendNoteOff(25,0,1); //turn midi note off 25 velocity 127, midi channel 1.
button2state = 0;
}
if ((button3beans == LOW) && (button3state == 0))
{ MIDI.sendNoteOn(26,127,1); //turn midi note on 26 velocity 127, midi channel 1.
button3state = 1;}
if ((button3beans == HIGH) && (button3state == 1))
{ MIDI.sendNoteOff(26,0,1); //turn midi note off 26 velocity 127, midi channel 1.
button3state = 0;
}
if ((button4beans == LOW) && (button4state == 0))
{ MIDI.sendNoteOn(27,127,1); //turn midi note on 27 velocity 127, midi channel 1.
button4state = 1;}
if ((button4beans == HIGH) && (button4state == 1))
{ MIDI.sendNoteOff(27,0,1); //turn midi note off 27 velocity 127, midi channel 1.
button4state = 0;
}
if ((button5beans == LOW) && (button5state == 0))
{ MIDI.sendNoteOn(28,127,1); //turn midi note on 28 velocity 127, midi channel 1.
button5state = 1;}
if ((button5beans == HIGH) && (button5state == 1))
{ MIDI.sendNoteOff(28,0,1); //turn midi note off 28 velocity 127, midi channel 1.
button5state = 0;
}
if ((button6beans == LOW) && (button6state == 0))
{ MIDI.sendNoteOn(29,127,1); //turn midi note on 29 velocity 127, midi channel 1.
button6state = 1;}
if ((button6beans == HIGH) && (button6state == 1))
{ MIDI.sendNoteOff(29,0,1); //turn midi note off 29 velocity 127, midi channel 1.
button6state = 0;
}
if ((button7beans == LOW) && (button7state == 0))
{ MIDI.sendNoteOn(30,127,1); //turn midi note on 30 velocity 127, midi channel 1.
button7state = 1;}
if ((button7beans == HIGH) && (button7state == 1))
{ MIDI.sendNoteOff(30,0,1); //turn midi note off 30 velocity 127, midi channel 1.
button7state = 0;
}
if ((button8beans == LOW) && (button8state == 0))
{ MIDI.sendNoteOn(31,127,1); //turn midi note on 31 velocity 127, midi channel 1.
button8state = 1;}
if ((button8beans == HIGH) && (button8state == 1))
{ MIDI.sendNoteOff(31,0,1); //turn midi note off 31 velocity 127, midi channel 1.
button8state = 0;
}
if ((button9beans == LOW) && (button9state == 0))
{ MIDI.sendNoteOn(32,127,1); //turn midi note on 32 velocity 127, midi channel 1.
button9state = 1;}
if ((button9beans == HIGH) && (button9state == 1))
{ MIDI.sendNoteOff(32,0,1); //turn midi note off 32 velocity 127, midi channel 1.
button9state = 0;
}
if ((button10beans == LOW) && (button10state == 0))
{ MIDI.sendNoteOn(33,127,1); //turn midi note on 33 velocity 127, midi channel 1.
button10state = 1;}
if ((button10beans == HIGH) && (button10state == 1))
{ MIDI.sendNoteOff(33,0,1); //turn midi note off 33 velocity 127, midi channel 1.
button10state = 0;
}
if ((button11beans == LOW) && (button11state == 0))
{ MIDI.sendNoteOn(34,127,1); //turn midi note on 34 velocity 127, midi channel 1.
button11state = 1;}
if ((button11beans == HIGH) && (button11state == 1))
{ MIDI.sendNoteOff(34,0,1); //turn midi note off 34 velocity 127, midi channel 1.
button11state = 0;
}
if ((button12beans == LOW) && (button12state == 0))
{ MIDI.sendNoteOn(35,127,1); //turn midi note on 35 velocity 127, midi channel 1.
button12state = 1;}
if ((button12beans == HIGH) && (button12state == 1))
{ MIDI.sendNoteOff(35,0,1); //turn midi note off 35 velocity 127, midi channel 1.
button12state = 0;
}
if ((button13beans == LOW) && (button13state == 0))
{ MIDI.sendNoteOn(36,127,1); //turn midi note on 36 velocity 127, midi channel 1.
button13state = 1;}
if ((button13beans == HIGH) && (button13state == 1))
{ MIDI.sendNoteOff(36,0,1); //turn midi note off 36 velocity 127, midi channel 1.
button13state = 0;
}
}
merci d'avance ![]()
Cyril



