cs-midi-docs/docs/examples/03-interfaces/01-ble-midi.md

41 lines
1.1 KiB
Markdown

# BLE MIDI
Bluetooth Low Energy MIDI interface setup.
Build with `CS_MIDI_HID_KEYBOARD=ON` to also advertise as a BLE HID
keyboard with a Battery Service. This serves two purposes:
1. **Auto-reconnect** — the host OS auto-reconnects to bonded HID
peripherals on power-up, which brings up the MIDI service without
manual intervention.
2. **Battery level** — the standard BLE Battery Service (UUID 0x180F)
reports charge level to the OS. Call `setBLEBatteryLevel(percent)` from
your application to update it (e.g. from an ADC reading on a voltage
divider).
No keyboard input is ever sent — the HID descriptor exists solely to
trigger the OS auto-connect behavior and surface the battery indicator.
```cpp pico
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include <cs_midi.h>
using namespace cs;
BluetoothMIDI_Interface midi;
NoteButton button {5, {MIDI_Notes::C[4], Channel_1}};
CCRotaryEncoder enc {{0, 2}, {16, Channel_1}, 1, 4};
int main() {
stdio_init_all();
if (cyw43_arch_init()) return 1;
Control_Surface.begin();
while (true) {
Control_Surface.loop();
sleep_ms(1);
}
}
```