本帖最后由 dcexpert 于 2021-6-7 22:06 编辑
基于 nRF52840 和circuitpython的无线midi控制。
需要安装的库
- adafruit_ble
- adafruit_ble_midi.mpy
- adafruit_midi
参考代码
import time
# Midi
import adafruit_midi
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
# BLE Midi
import adafruit_ble
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
import adafruit_ble_midi
# Setup BLE Midi
midi_service = adafruit_ble_midi.MIDIService()
advertisement = ProvideServicesAdvertisement(midi_service)
midi = adafruit_midi.MIDI(midi_out=midi_service, out_channel=0)
ble = adafruit_ble.BLERadio()
# Make BLE Device visible
print("Waiting for BLE MIDI connection")
ble.start_advertising(advertisement)
while True:
# If not connected, don't execute the rest of the code
while not ble.connected:
pass
print("Connected")
while ble.connected:
midi.send(NoteOn(70, 127))
print("NOTE ON")
time.sleep(1)
midi.send(NoteOff(0, 0))
print("NOTE OFF")
time.sleep(1)
# If disconnect, wait for reconnection
print("Disconnected")
print("Advertising BLE")
ble.start_advertising(advertisement)
|