Last active
October 2, 2020 15:44
-
-
Save chonz0/7bd92fc39de00e272b9eeb2570768e51 to your computer and use it in GitHub Desktop.
MIDIUSB example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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