I have the following piece of code, but the 2 callback functions are never actually called.
I'm using hairless midi-serial bridge, loopmidi, and ableton live.
#include <MIDI.h>
#include <LiquidCrystal.h>
const int rs = 53, en = 51, d4 = 49, d5 = 47, d6 = 45, d7 = 43;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
MIDI_CREATE_DEFAULT_INSTANCE();
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
lcd.print(pitch);
}
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
lcd.print(pitch);
}
void setup()
{
Serial.begin(115200);
lcd.begin(16, 2);
MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop()
{
MIDI.read();
}
#include <MIDI.h>
struct MySettings : public midi::DefaultSettings {
static const long BaudRate = 115200;
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings)
void setup() {
MIDI.begin();
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
}
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
digitalWrite(13, HIGH);
}
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
digitalWrite(13, LOW);
}
The RX led blinks on the Arduino when midi is sent to it.
I tried the following:
Looking if the midi-serial bridge actually works: Yup
Ruling out the LCD by turning pin13 on or off when the 2 callback functions are called, nothing happens.
Setting the midi library to listen on all channels(MIDI.begin(MIDI_CHANNEL_OMNI); )
Using another program instead of Ableton Live, still didn't work.
Basically, the midi library refuses to call the callback function until ~10 notes are sent to it. Don't ask me why. I just connected a midi controller to it, and started pushing buttons randomly and a few seconds later it started working. So I loaded up the code from my last post, and sure enough, after sending a few midi notes to the arduino it starts working.
Basically, the midi library refuses to call the callback function until ~10 notes are sent to it. Don't ask me why. I just connected a midi controller to it, and started pushing buttons randomly and a few seconds later it started working. So I loaded up the code from my last post, and sure enough, after sending a few midi notes to the arduino it starts working.
That can't be right. Last time I used it, it registered notes from the moment I started sending.