Skip to content

Instantly share code, notes, and snippets.

@lean8086
Last active February 6, 2024 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lean8086/ec8da7486ec3621f9f0b90542a06fcea to your computer and use it in GitHub Desktop.
Save lean8086/ec8da7486ec3621f9f0b90542a06fcea to your computer and use it in GitHub Desktop.
// Channel can be a number from 0 to 15. Typically displayed as 1 to 16.
byte channel = 0;
// ...
void setup() {
// ...
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
}
void loop() {
if (digitalRead(18) == LOW) { channel = 0 }
if (digitalRead(19) == LOW) { channel = 1 }
// ...
}
void noteOn(byte pitch) {
MidiUSB.sendMIDI({0x09, 0x90 | channel, pitch, 127});
MidiUSB.flush();
}
void noteOff(byte pitch) {
MidiUSB.sendMIDI({0x08, 0x80 | channel, pitch, 0});
MidiUSB.flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment