examples/bluetooth/ble_uart_peripheral.py: Add usage demo.
This commit is contained in:
parent
2c1f269918
commit
9c5262f25e
|
@ -75,5 +75,29 @@ class BLEUART:
|
|||
self._ble.gap_advertise(interval_us, adv_data=self._payload)
|
||||
|
||||
|
||||
# ble = bluetooth.BLE()
|
||||
# uart = BLEUART(ble)
|
||||
def demo():
|
||||
import time
|
||||
|
||||
ble = bluetooth.BLE()
|
||||
uart = BLEUART(ble)
|
||||
|
||||
def on_rx():
|
||||
print('rx: ', uart.read().decode().strip())
|
||||
|
||||
uart.irq(handler=on_rx)
|
||||
nums = [4, 8, 15, 16, 23, 42]
|
||||
i = 0
|
||||
|
||||
try:
|
||||
while True:
|
||||
uart.write(str(nums[i]) + '\n')
|
||||
i = (i + 1) % len(nums)
|
||||
time.sleep_ms(1000)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
uart.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
demo()
|
||||
|
|
Loading…
Reference in New Issue