Here is the schematic diagram to build 32 channels MIDI trigger board to use with Arduino.
Arduino sketch:
- // TAPDRUM 32 input triggers MIDI board
- // Mux address pins
- #define addr1 4
- #define addr2 5
- #define addr3 6
- #define addr4 3
- int ledPin = 13 ; // Led connected to digital pin 13
- int pzo = 0 ; // Piezo connected to analog channels start with analog 0
- int mux=0 ; // multiplexer address start with address 0
- int val[32] ; // array to store the value read from the sensor pin
- int valold[32];
- // 32 address location for MIDI percussion/drum notes
- // General MIDI drum notes reference
- //note=35 Bass Drum 2
- //note=36 Bass Drum 1
- //note=37 Side Stick
- //note=38 Snare Drum 1
- //note=39 Hand Clap
- //note=40 Snare Drum 2
- //notemutiplex_var1_scheet=41 Low Tom 2
- //note=42 Closed Hi-hat
- //...... note=81 open triangle
- int loc[32] = {35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66};
- int i = 0;
- int inh=0;
- int statePin = 0; // variable used to store the last LED status , to toglle the light
- byte THRESHOLD = 5; // threshold value to decide when the detected sound is a knock or not
- void setup()
- {
- pinMode(ledPin, OUTPUT); // declare the ledPin as OUTPUT
- pinMode(addr1, OUTPUT);
- pinMode(addr2, OUTPUT);
- pinMode(addr3, OUTPUT);
- pinMode(addr4, OUTPUT);
- //Arduino Leonardo standard MIDI
- Serial.begin(31250); //standard MIDI
- //Serial.begin(57600); // set MIDI baud rate for Spikienzilab.com serial to MIDI converter
- //Serial.begin(31250); //standard MIDI
- //Serial.begin(38400); // Roland USB MIDI
- //Serial.begin(36000); // set MIDI baud rate for ser2MIDI software
- }
- void loop(){
- digitalWrite(addr4, LOW);
- for (mux=0; mux <8; mux++) {
- // set control pins on the multiplexers
- digitalWrite(addr1, (mux&7)>>2);//bit3
- digitalWrite(addr2, (mux&3)>>1);//bit2
- digitalWrite(addr3, (mux&1) );//bit1
- // deal with piezo analog channel loop
- for (pzo=0; pzo<4; pzo++)
- {
- valold[mux+8*pzo]= val[mux+8*pzo];
- val[mux+8*pzo] = analogRead(pzo)/8;
- if (val[mux+8*pzo] >=THRESHOLD & valold[mux+8*pzo] >=val[mux+8*pzo])
- //if (val > 20)
- {
- //remove following comments to check trigger input and value
- // Serial.print ("trigger-->");
- // Serial.print (mux+8*pzo);
- // Serial.print ("--value---->");
- // Serial.println (valold[mux+8*pzo]);
- noteOn (153 , loc[mux+8*pzo], valold[mux+8*pzo]);
- digitalWrite(ledPin, HIGH);
- delay(2);
- noteOn (137 , loc[mux+8*pzo], 0);
- digitalWrite(ledPin, LOW);
- delay(2);
- valold[mux+8*pzo]= 0;
- val[mux+8*pzo]= 0;
- }
- }
- }
- }
- // plays a MIDInote doesn't check to see that cmd is greater than 127 or that data values are less than 127
- //void noteOn(unsigned char cmd, unsigned char data1, unsigned char data2) {
- // Serial.print(cmd);
- // Serial.print(data1);
- // Serial.print(data2);
- void noteOn(int cmd, int data1, int data2) {
- Serial.write(cmd);
- Serial.write(data1);
- Serial.write(data2);
- //For arduino leonardo
- // Serial1.write(cmd);
- // Serial1.write(data1);
- // Serial1.write(data2);
- }