Created
December 17, 2025 16:22
-
-
Save ypelletier/f2ef8107457c7aeb626c58cf072fa8dd to your computer and use it in GitHub Desktop.
Batterie MIDI à 5 tambours contrôlée par Arduino.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /******************************************************** | |
| Batterie MIDI à 5 tambours contrôlée par Arduino. | |
| Pour plus d'informations: | |
| https://electroniqueamateur.blogspot.com/2025/12/transformation-dune-batterie-guitar.html | |
| *********************************************************/ | |
| const int nombreDeTambours = 5; | |
| const int seuilmin[] = {12, 8, 5, 4, 5}; // signal analogique nécessaire pour qu'on détecte une frappe | |
| unsigned long debutCoup[nombreDeTambours]; // moment où un coup a été détecté | |
| const unsigned long duree = 20; // délai pendant lequel on n'essaie pas de détecter la prochaine frappe. | |
| const int entree[] = {A0, A1, A2, A3, A4}; // les cinq entrées analogiques reliées à un piézo | |
| const int midiCanal = 9; // ce canal est réservé aux percussions dans la norme General MIDI | |
| const int midiNotes[] = {47, 38, 48, 49, 50}; // 35 à 81 dans la norme General MIDI; chaque note est associée à un instrument | |
| void noteOn(int cmd, int pitch, int velocity) { | |
| Serial.write(cmd); | |
| Serial.write(pitch); | |
| Serial.write(velocity); | |
| } | |
| void setup() { | |
| Serial.begin(31250); // réglage du baud rate à la norme MIDI | |
| } | |
| void loop() { | |
| int mesure; | |
| unsigned long tempsMesure; | |
| //on scrute chaque tambour, un après l'autre | |
| for (int pad = 0; pad < nombreDeTambours; pad++) { | |
| tempsMesure = millis(); | |
| if ((tempsMesure - debutCoup[pad]) > duree) // le dernier coup détecté a eu lieu au moins 20 ms plus tôt | |
| { | |
| mesure = analogRead(entree[pad]); | |
| if (mesure > seuilmin[pad]) { | |
| debutCoup[pad] = tempsMesure; | |
| noteOn(0x90 + midiCanal, midiNotes[pad], 127); | |
| noteOn(0x90 + midiCanal, midiNotes[pad], 0); // noteOff | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment