75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
#include <BLEMIDI.h>
|
|
|
|
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
|
|
//#include <hardware/BLEMIDI_ESP32.h>
|
|
//#include <hardware/BLEMIDI_nRF52.h>
|
|
//#include <hardware/BLEMIDI_ArduinoBLE.h>
|
|
|
|
BLEMIDI_CREATE_DEFAULT_INSTANCE()
|
|
|
|
bool isConnected = false;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// -----------------------------------------------------------------------------
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
while (!Serial);
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
|
|
BLEMIDI.setHandleConnected(OnConnected);
|
|
BLEMIDI.setHandleDisconnected(OnDisconnected);
|
|
|
|
MIDI.setHandleSystemExclusive(OnMidiSysEx);
|
|
|
|
// Listen for MIDI messages on channel 1
|
|
MIDI.begin();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// -----------------------------------------------------------------------------
|
|
void loop()
|
|
{
|
|
// Listen to incoming notes
|
|
MIDI.read();
|
|
}
|
|
|
|
// ====================================================================================
|
|
// Event handlers for incoming MIDI messages
|
|
// ====================================================================================
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Device connected
|
|
// -----------------------------------------------------------------------------
|
|
void OnConnected() {
|
|
isConnected = true;
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Device disconnected
|
|
// -----------------------------------------------------------------------------
|
|
void OnDisconnected() {
|
|
isConnected = false;
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// -----------------------------------------------------------------------------
|
|
void OnMidiSysEx(byte* data, unsigned length) {
|
|
Serial.print(F("SYSEX: ("));
|
|
Serial.print(length);
|
|
Serial.print(F(" bytes) "));
|
|
for (uint16_t i = 0; i < length; i++)
|
|
{
|
|
Serial.print(data[i], HEX);
|
|
Serial.print(" ");
|
|
}
|
|
Serial.println();
|
|
}
|