Hello there!
I'm trying to read MIDI from an electronic keyboard and would appreciate if you could tell me if I'm properly reading MIDI over a USB connection. I'm going to control some LEDs, but I need to get this part down before I can move forward to LED manipulation.
The code I'm using is as such
#include <MIDIUSB.h>
#include <MIDIUSB_Defs.h>
#include <frequencyToNote.h>
#include <pitchToFrequency.h>
#include <pitchToNote.h>
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
// The notes on a keyboard go from 21 to 108. To get the first note to correspond to the first LED, I'm going to subtract 21 from the pitch number and store it.
short R = pitch-21;
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
//Here, we will a. correlate a MIDI note to a key b. turn off that key's associated light
short R = pitch-21;
}
void setup() {
}
void loop() {
midiEventPacket_t rx;
rx = MidiUSB.read();
}
The code here is based off the MIDIUSB github's "read" example.
My main question is: I believe "pitch" is the numeric representation of the midi note. Is this correct? If using MIDIUSB, do I need to specify noteOn and noteOFF like with the standard serial MIDI library? Once I know how to move forward, I already know how to play with the lights.
Thank you for your time.