无线 midi 控制

Adafruit CircuitPython相关
MicroPython重要分支
回复
头像
shaoziyang
帖子: 1992
注册时间: 2019年 10月 21日 13:48

无线 midi 控制

#1

帖子 shaoziyang » 2021年 6月 7日 22:01

基于 nRF52840 的无线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)
隐藏内容
你必须登入/注册才可观看隐藏内容
 
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章