Skip to content

Instantly share code, notes, and snippets.

@RyoKosaka
Last active September 4, 2023 14:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save RyoKosaka/9851abbf0393aa6790a14c4806656f04 to your computer and use it in GitHub Desktop.
Save RyoKosaka/9851abbf0393aa6790a14c4806656f04 to your computer and use it in GitHub Desktop.
//Arduino-BLE-MIDI Library
//https://github.com/lathoub/Arduino-BLE-MIDI
#include <BLEMIDI_Transport.h>
#include <hardware/BLEMIDI_ESP32.h>
BLEMIDI_CREATE_DEFAULT_INSTANCE()
void setup() {
pinMode(12, OUTPUT);
pinMode(14, OUTPUT);
MIDI.begin();
}
void loop() {
uint8_t data1;
uint8_t data2;
if (MIDI.read()) { //when get MIDI signal
switch (MIDI.getType()) {
case midi::NoteOn:
data1 = MIDI.getData1(); //get note number
data2 = MIDI.getData2(); //get velocity (this value is not used in this code.)
if (data1 > 60) {
digitalWrite(12, HIGH);
} else {
digitalWrite(14, HIGH);
}
break;
case midi::NoteOff:
data1 = MIDI.getData1(); //get note number
data2 = MIDI.getData2(); //get velocity (this value is not used in this code.)
if (data1 > 60) {
digitalWrite(12, LOW);
} else {
digitalWrite(14, LOW);
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment