I am working on a DIY midi controller using piezo sensors and an arduino board. The idea came to me after seeing todbot " musical arduino - midi drum kit"
Here is the basic skerch
* MIDI Drum Kit
* -------------
* Convert Arduino to a MIDI controller piezo 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
*
* 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
* pin 5 - Arduino D1 (TX)
* all other pins - unconnected
// what midi channel we're sending on
// ranges from 0-15
#define drumchan 1
// general midi drum notes
#define note_Middle C 60 - E 89
// define the pins we use
#define piezoZeroPin 0
#define piezoOnePin 1
#define ledPin 13 // for midi out status
// analog threshold for piezo sensing
#define PIEZOTHRESHOLD 100
int val,t;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(31250); // set MIDI baud rate
}
void loop() {
// deal with first piezo, this is kind of a hack
val = analogRead(piezoZeroPin);
if( val >= PIEZOTHRESHOLD ) {
t=0;
while(analogRead(piezoZeroPin) >= PIEZOTHRESHOLD/2) {
t++;
}
noteOn(drumchan,note_Middle C, t*2);
delay(t);
noteOff(drumchan,note_Middle C,0);
}
// deal with second piezos, this is kind of a hack
val = analogRead(piezoOnePin);
if( val >= PIEZOTHRESHOLD ) {
t=0;
while(analogRead(piezoOnePin) >= PIEZOTHRESHOLD/2) {
t++;
}
noteOn(drumchan,note_C#, t*2);
delay(t);
noteOff(drumchan,note_C#,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);
}
Next to expand the number of inputs on the arduino I added 4 multiplexers (4051)
The Mux:
http://arduino.cc/forum/index.php/topic,51551.msg368972.html#msg368972