diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2019-10-22 01:04:48 +1100 |
---|---|---|
committer | Jim Mussared <jim.mussared@gmail.com> | 2019-10-22 14:30:23 +1100 |
commit | 9c5262f25ef29950da241380c76e035b3a8cec38 (patch) | |
tree | 4d2fcb899ee85967567550fdb6f516a0e6d9dbea | |
parent | 2c1f269918331a50678119410219e965fcdb822e (diff) | |
download | micropython-9c5262f25ef29950da241380c76e035b3a8cec38.tar.gz micropython-9c5262f25ef29950da241380c76e035b3a8cec38.zip |
examples/bluetooth/ble_uart_peripheral.py: Add usage demo.
-rw-r--r-- | examples/bluetooth/ble_uart_peripheral.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/examples/bluetooth/ble_uart_peripheral.py b/examples/bluetooth/ble_uart_peripheral.py index 3508a15e7b..90cdbcaf52 100644 --- a/examples/bluetooth/ble_uart_peripheral.py +++ b/examples/bluetooth/ble_uart_peripheral.py @@ -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() |