Go Down

Topic: MIDI Library help (Read 1 time) previous topic - next topic

I'm having trouble using the MIDI Library.  Specifically the callback functions. 

http://arduinomidilib.fortyseveneffects.com/index.html

I downloaded this library and installed it.  Im trying to start from the example MIDI_Callbacks.  In order to see if the library is working, I'm simply trying to turn the pin 13 LED on and off on my Arduino UNO.  A midi note on would turn the LED on and a note off turns it off.  The only thing I've added to the example is a digitalWrite(led, HIGH) and a digitalWrite(led, LOW).

I'm using Hairless MIDI to serial bridge.  I can see the note on and off is getting to the arduino UNO.  the RX light lights up, but nothing ever lights up the pin13 LED.

I assume I'm missing something simple.  I'm new to this.  The code is below.  Any help would be greatly appreciated!
Clark

#include <MIDI.h>


int led = 13;

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here:
// http://arduinomidilib.sourceforge.net/class_m_i_d_i___class.html

void HandleNoteOn(byte channel, byte pitch, byte velocity)
{
    // Do whatever you want when you receive a Note On.
    digitalWrite(led, HIGH);
 
    if (velocity == 0)
    {
        // This acts like a NoteOff.
        digitalWrite(led, LOW);
    }
   
    // Try to keep your callbacks short (no delays ect)
    // otherwise it would slow down the loop() and have a bad impact
    // on real-time performance.
}

// -----------------------------------------------------------------------------

void setup()
{
   pinMode(led, OUTPUT);
    // Initiate MIDI communications, listen to all channels
    MIDI.begin(MIDI_CHANNEL_OMNI);   
 
    // Connect the HandleNoteOn function to the library,
    // so it is called upon reception of a NoteOn.
    MIDI.setHandleNoteOn(HandleNoteOn);  // Put only the name of the function
}


void loop()
{
    // Call MIDI.read the fastest you can for real-time performance.
    MIDI.read();
   
    // There is no need to check if there are messages incoming
    // if they are bound to a Callback function.
    // The attached method will be called automatically
    // when the corresponding message has been received.
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy