summaryrefslogtreecommitdiffstatshomepage
path: root/examples/bluetooth/ble_uart_peripheral.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/bluetooth/ble_uart_peripheral.py')
-rw-r--r--examples/bluetooth/ble_uart_peripheral.py28
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()