Skip to content

Instantly share code, notes, and snippets.

@chonz0
Last active October 2, 2020 15:44
Show Gist options
  • Save chonz0/7bd92fc39de00e272b9eeb2570768e51 to your computer and use it in GitHub Desktop.
Save chonz0/7bd92fc39de00e272b9eeb2570768e51 to your computer and use it in GitHub Desktop.
MIDIUSB example
#include <MIDIUSB.h>
int note;
int previous_note = 0;
int current_note = 0;
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void setup() {}
void loop() {
// read finger position and map to a note
readFingerPositionAndTranslateToNote(); // <- you should use your function here
if (current_note != previous_note) {
// stop playing previous note
noteOff(0, previous_note, 127);
MidiUSB.flush();
// where "note" is a MIDI note number in this table https://computermusicresource.com/midikeys.html
noteOn(0, note, 127);
MidiUSB.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment