@@ -35,9 +35,6 @@ Installing from PyPI
3535.. note :: This library is not available on PyPI yet. Install documentation is included
3636 as a standard element. Stay tuned for PyPI availability!
3737
38- .. todo :: Remove the above note if PyPI version is/will be available at time of release.
39- If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
40-
4138On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4239PyPI <https://pypi.org/project/adafruit-circuitpython-ble_midi/> `_. To install for current user:
4340
@@ -63,7 +60,55 @@ To install in a virtual environment in your current project:
6360 Usage Example
6461=============
6562
66- .. todo :: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
63+ .. code-block :: python
64+
65+ """
66+ This example sends MIDI out. It sends NoteOn and then NoteOff with a random pitch bend.
67+ """
68+
69+ import time
70+ import random
71+ import adafruit_ble
72+ from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
73+ import adafruit_ble_midi
74+ import adafruit_midi
75+ from adafruit_midi.control_change import ControlChange
76+ from adafruit_midi.note_off import NoteOff
77+ from adafruit_midi.note_on import NoteOn
78+ from adafruit_midi.pitch_bend import PitchBend
79+
80+ # Use default HID descriptor
81+ midi_service = adafruit_ble_midi.MIDIService()
82+ advertisement = ProvideServicesAdvertisement(midi_service)
83+ # advertisement.appearance = 961
84+
85+ ble = adafruit_ble.BLERadio()
86+ if ble.connected:
87+ for c in ble.connections:
88+ c.disconnect()
89+
90+ midi = adafruit_midi.MIDI(midi_out = midi_service, out_channel = 0 )
91+
92+ print (" advertising" )
93+ ble.start_advertising(advertisement)
94+
95+ while True :
96+ print (" Waiting for connection" )
97+ while not ble.connected:
98+ pass
99+ print (" Connected" )
100+ while ble.connected:
101+ midi.send(NoteOn(44 , 120 )) # G sharp 2nd octave
102+ time.sleep(0.25 )
103+ a_pitch_bend = PitchBend(random.randint(0 , 16383 ))
104+ midi.send(a_pitch_bend)
105+ time.sleep(0.25 )
106+ # note how a list of messages can be used
107+ midi.send([NoteOff(" G#2" , 120 ), ControlChange(3 , 44 )])
108+ time.sleep(0.5 )
109+ print (" Disconnected" )
110+ print ()
111+ ble.start_advertising(advertisement)
67112
68113 Contributing
69114============
0 commit comments