Skip to content

Instantly share code, notes, and snippets.

@knatten
Created January 18, 2019 22:20
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 knatten/74b307a030020fedbf9620083e03410a to your computer and use it in GitHub Desktop.
Save knatten/74b307a030020fedbf9620083e03410a to your computer and use it in GitHub Desktop.
#include "MIDIUSB.h"
void setup() {
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
}
int noteToPin(uint8_t note) {
if (note == 0x24)
return A1;
if (note == 0x25)
return A2;
}
void noteOn(uint8_t note) { digitalWrite(noteToPin(note), HIGH); }
void noteOff(uint8_t note) { digitalWrite(noteToPin(note), LOW); }
void loop() {
midiEventPacket_t rx = MidiUSB.read();
if (rx.header != 0) {
if (rx.header == 0x09) {
noteOn(rx.byte2);
}
if (rx.header == 0x08) {
noteOff(rx.byte2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment