/* * MIDI Drum Kit * ------------- * Convert Arduino to a MIDI controller using various inputs and * the serial port as a MIDI output. * * This sketch is set up to send General MIDI (GM) drum notes * on MIDI channel 1, but it can be easily reconfigured for other * notes and channels * * It uses switch inputs to send MIDI notes of a fixed velocity with * note on time determined by duration of keypress and it uses * piezo buzzer elements as inputs to send MIDI notes of a varying velocity * & duration, depending on forced of impulse imparted to piezo sensor. * * To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino. * DIN-5 pinout is: _____ * pin 2 - Gnd / \ * pin 4 - 220 ohm resistor to +5V | 3 1 | MIDI jack * pin 5 - Arduino D1 (TX) | 5 4 | * all other pins - unconnected \__2__/ * On my midi jack, the color of the wires for the pins are: * 3 = n/c * 5 = black (blue) * 2 = red (red) * 4 = orange (yellow) * 1 = brown * * Based off of Tom Igoe's work at: * http://itp.nyu.edu/physcomp/Labs/MIDIOutput * * Created 25 October 2006 * copyleft 2006 Tod E. Kurt = PIEZOTHRESHOLD ) { t=0; while(analogRead(piezoAPin) >= PIEZOTHRESHOLD/2) { t++; } noteOn(drumchan,note_hihatopen, t*2); delay(t); noteOff(drumchan,note_hihatopen,0); } // deal with second piezos, this is kind of a hack val = analogRead(piezoBPin); if( val >= PIEZOTHRESHOLD ) { t=0; while(analogRead(piezoBPin) >= PIEZOTHRESHOLD/2) { t++; } noteOn(drumchan,note_crash, t*2); delay(t); noteOff(drumchan,note_crash,0); } } // Send a MIDI note-on message. Like pressing a piano key // channel ranges from 0-15 void noteOn(byte channel, byte note, byte velocity) { midiMsg( (0x90 | channel), note, velocity); } // Send a MIDI note-off message. Like releasing a piano key void noteOff(byte channel, byte note, byte velocity) { midiMsg( (0x80 | channel), note, velocity); } // Send a general MIDI message void midiMsg(byte cmd, byte data1, byte data2) { digitalWrite(ledPin,HIGH); // indicate we're sending MIDI data Serial.print(cmd, BYTE); Serial.print(data1, BYTE); Serial.print(data2, BYTE); digitalWrite(ledPin,LOW); }