Merge pull request #15 from spridget/patch-2

Update ble_midi_simpletest.py
This commit is contained in:
Scott Shawcroft 2025-08-25 11:35:25 -07:00 committed by GitHub
commit 3fd0c61ed5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,23 +37,29 @@ while True:
print("Waiting for connection") print("Waiting for connection")
while not ble.connected: while not ble.connected:
pass pass
print("Connected") print("Connected; waiting for pairing")
# Sleep briefly so client can get ready and send setup for connection in ble.connections:
# writes to the MIDIService. 0.5secs was insufficient. while not connection.paired:
time.sleep(1.0) if not connection.connected:
# Send one unique NoteOn/Off at the beginning to check that the break
# delay is sufficient. if connection.paired:
midi.send(NoteOn(20, 99)) print("Paired; sending MIDI messages")
midi.send(NoteOff(20, 99)) # Sleep briefly so client can get ready and send setup
while ble.connected: # writes to the MIDIService. 0.5secs was insufficient.
midi.send(NoteOn(44, 120)) # G sharp 2nd octave time.sleep(3.0)
time.sleep(0.25) # Send one unique NoteOn/Off at the beginning to check that the
a_pitch_bend = PitchBend(random.randint(0, 16383)) # delay is sufficient.
midi.send(a_pitch_bend) midi.send(NoteOn(20, 99))
time.sleep(0.25) midi.send(NoteOff(20, 99))
# note how a list of messages can be used while ble.connected:
midi.send([NoteOff("G#2", 120), ControlChange(3, 44)]) midi.send(NoteOn(44, 120)) # G sharp 2nd octave
time.sleep(0.5) time.sleep(0.25)
a_pitch_bend = PitchBend(random.randint(0, 16383))
midi.send(a_pitch_bend)
time.sleep(0.25)
# note how a list of messages can be used
midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
time.sleep(0.5)
print("Disconnected") print("Disconnected")
print() print()
ble.start_advertising(advertisement) ble.start_advertising(advertisement)