i dont understan how the midiusb library receive the message.
what i want to do is when the arsuino receive note42 velocity 127 to turn on a led.
and when arduino receive note 42 velocity 0 to turn off the led.
something i do very wrong in the code.
i add a line to the setup just to see if the code will light the led, and is ok.. so no conection problem.
any idea what i am missing
#include "MIDIUSB.h"// Library from here https://github.com/FortySevenEffects/arduino_midi_library
#include "LedControl.h"
LedControl lc = LedControl(10, 8, 9, 1);
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
Serial.begin(115200);
lc.setLed (0, 1, 1, true); // turn 1 led on to see if the code is working
}
void loop() {
midiEventPacket_t rx;
do {
rx = MidiUSB.read();
if (rx.header == 42) { // if note 42 comes in then one led will lit in max7219
lc.setLed (0, 7, 7, true);
}
} while (rx.header == 0); // if there no not come in the led will turn off
lc.setLed (0, 7, 7, false);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}