|
37 | 37 | print("Waiting for connection") |
38 | 38 | while not ble.connected: |
39 | 39 | pass |
40 | | - print("Connected") |
41 | | - # Sleep briefly so client can get ready and send setup |
42 | | - # writes to the MIDIService. 0.5secs was insufficient. |
43 | | - time.sleep(1.0) |
44 | | - # Send one unique NoteOn/Off at the beginning to check that the |
45 | | - # delay is sufficient. |
46 | | - midi.send(NoteOn(20, 99)) |
47 | | - midi.send(NoteOff(20, 99)) |
48 | | - while ble.connected: |
49 | | - midi.send(NoteOn(44, 120)) # G sharp 2nd octave |
50 | | - time.sleep(0.25) |
51 | | - a_pitch_bend = PitchBend(random.randint(0, 16383)) |
52 | | - midi.send(a_pitch_bend) |
53 | | - time.sleep(0.25) |
54 | | - # note how a list of messages can be used |
55 | | - midi.send([NoteOff("G#2", 120), ControlChange(3, 44)]) |
56 | | - time.sleep(0.5) |
| 40 | + print("Connected; waiting for pairing") |
| 41 | + for connection in ble.connections: |
| 42 | + while not connection.paired: |
| 43 | + if not connection.connected: |
| 44 | + break |
| 45 | + if connection.paired: |
| 46 | + print("Paired; sending MIDI messages") |
| 47 | + # Sleep briefly so client can get ready and send setup |
| 48 | + # writes to the MIDIService. 0.5secs was insufficient. |
| 49 | + time.sleep(3.0) |
| 50 | + # Send one unique NoteOn/Off at the beginning to check that the |
| 51 | + # delay is sufficient. |
| 52 | + midi.send(NoteOn(20, 99)) |
| 53 | + midi.send(NoteOff(20, 99)) |
| 54 | + while ble.connected: |
| 55 | + midi.send(NoteOn(44, 120)) # G sharp 2nd octave |
| 56 | + time.sleep(0.25) |
| 57 | + a_pitch_bend = PitchBend(random.randint(0, 16383)) |
| 58 | + midi.send(a_pitch_bend) |
| 59 | + time.sleep(0.25) |
| 60 | + # note how a list of messages can be used |
| 61 | + midi.send([NoteOff("G#2", 120), ControlChange(3, 44)]) |
| 62 | + time.sleep(0.5) |
57 | 63 | print("Disconnected") |
58 | 64 | print() |
59 | 65 | ble.start_advertising(advertisement) |
0 commit comments