Here's the code I'm using (below). I'm using MIDIOX to send midi messages via a USB to MIDI cable. The code should do 2 things as a test, 1) turn on the LED when a noteOn is sent and send a noteOn message every second.
my hardware is a Uno R3 (programmed via USB). I was able to figure out that the Olimex MIDI shield has a jumper that you can remove to program it, and then replace to run it. This way I don't have to remove the shield every time.
There's a lot commented out, because I couldn't even get simple things to work, let alone the rest.
#include <MIDI.h>
// set NRPN to set volume to zero for part xyz
// read existing program/patch number ???
// send stop control
int ledPinRed = 06; // LED connected to digital pin 6
int ledPinGrn = 07; // LED connected to digital pin 7
void HandleNoteOn (byte channel, byte note, byte velocity){
//int program =0; //program or patch always begins at 0
//if note1 or note2 is sent, send program change control to go up or down
//if (note == 60){ //need to get the actual note number that I'll assign
// MIDI.sendProgramChange(1,10);
digitalWrite(ledPinGrn, HIGH); // sets the LED on
delay(1000); // waits for a second;
digitalWrite(ledPinGrn, LOW); //set the LED off
//}
//if (note == 62){ //need to get the actual note number that I'll assign
// MIDI.sendProgramChange(2,10);
// digitalWrite(ledPinRed, HIGH); // sets the LED on
//delay(1000); // waits for a second;
// digitalWrite(ledPinRed, LOW); //set the LED off
// }
}
//if note3 is sent, send nrpn to set volume to zero
void setup() {
pinMode(ledPinRed, OUTPUT); // sets the digital pin as output
pinMode(ledPinGrn, OUTPUT); // sets the digital pin as output
//int program =0; //program or patch hardcoded to begin at zero
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(HandleNoteOn);
// MIDI.sendProgramChange((program),10); //channel is hard coded to 10 for now
}
void loop () {
MIDI.read(); //is there incoming MIDI?
// LED Tests
//digitalWrite(ledPinGrn, HIGH); // sets the LED on
//delay(1000); // waits for a second
//digitalWrite(ledPinGrn, LOW); // sets the LED off
//delay(1000); // waits for a second
MIDI.sendNoteOn(60,127,10);
delay(1000);
MIDI.sendNoteOff(60,127,10);
}