I think I'm going to build an electronic drum kit with my Arduino. I just wrote a bit of code for a bass pedal:
int butpin = 2;
int last;
int but;
void setup() {
Serial.begin(31250);
pinMode(butpin, INPUT);
}
void loop() {
but = digitalRead(butpin);
if (but == HIGH && last == 0){
noteOff(1, 20, 0);
last = 1;
} else{
}
if (but == LOW && last == 1){
noteOn(1, 20, 64);
last = 0;
} else {
}
// delay(1);
}
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | (channel & 0xf)), note, velocity);
}
// Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | (channel & 0xf)), 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);
}
When I press the pedal it sends a midi note(yippy). The only issue is I can hear the lag. Right now I have my Arduino hooked up to a USB1.1 port, will I gain any speed by using a USB2.0 port? Is there any way for me to improve this performance? My expansion plans involve piezos and the analog pins. There isn't much point in continuing if I can't significantly reduce this lag.
Right now I'm running the Roland Serial Midi driver.
Thanks in advance.