Thank you for your help.
Just to follow up on this. I ended up with this code:
const int LEDpin = 13; // Indicator LED
const int kickdrum = 36; // MIDI note of the kick drum
int kick = 0; // Just a variable for setting kick detected
void setup() {
ACSR =
(0<<ACD) | // Analog Comparator: Enabled
(0<<ACBG) | // Analog Comparator Bandgap Select: AIN0 is applied to the positive input
(0<<ACO) | // Analog Comparator Output: Off
(1<<ACI) | // Analog Comparator Interrupt Flag: Clear Pending Interrupt
(1<<ACIE) | // Analog Comparator Interrupt: Enabled
(0<<ACIC) | // Analog Comparator Input Capture: Disabled
(1<<ACIS1) | (1<ACIS0); // Analog Comparator Interrupt Mode: Comparator Interrupt on Rising Output Edge
pinMode(LEDpin, OUTPUT); // Set the state of the LED I/O pin
Serial.begin(31250); // Set MIDI bitrate
blink(3);
}
void loop() {
if(kick){
noteOn(0x90, kickdrum, 0x40); // Send the MIDI note to the guitar hero drum set
blink(1); // Flash the LED if a kick is detected
delay(50); // Debounce - just in case
kick=0; // Reset the kick detected
}
}
ISR(ANALOG_COMP_vect)
{
kick=1; // Kick detected
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(byte cmd, byte data1, byte data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}
void blink(int howManyTimes) {
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(LEDpin, HIGH);
delay(10);
digitalWrite(LEDpin, LOW);
}
}
It seems to work fine with a Guitar Hero drum set, a Roland KD-8 electric drum trigger and a 4.7V zener, a voltage divider (2*390k) for the comperator reference and a 220 ohm for the MIDI output.