Skip to content

Commit 9c5262f

Browse files
committed
examples/bluetooth/ble_uart_peripheral.py: Add usage demo.
1 parent 2c1f269 commit 9c5262f

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

examples/bluetooth/ble_uart_peripheral.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,29 @@ def _advertise(self, interval_us=500000):
7575
self._ble.gap_advertise(interval_us, adv_data=self._payload)
7676

7777

78-
# ble = bluetooth.BLE()
79-
# uart = BLEUART(ble)
78+
def demo():
79+
import time
80+
81+
ble = bluetooth.BLE()
82+
uart = BLEUART(ble)
83+
84+
def on_rx():
85+
print('rx: ', uart.read().decode().strip())
86+
87+
uart.irq(handler=on_rx)
88+
nums = [4, 8, 15, 16, 23, 42]
89+
i = 0
90+
91+
try:
92+
while True:
93+
uart.write(str(nums[i]) + '\n')
94+
i = (i + 1) % len(nums)
95+
time.sleep_ms(1000)
96+
except KeyboardInterrupt:
97+
pass
98+
99+
uart.close()
100+
101+
102+
if __name__ == '__main__':
103+
demo()

0 commit comments

Comments
 (0)