|
9 | 9 | import digitalio |
10 | 10 |
|
11 | 11 | from adafruit_crickit import crickit |
12 | | -from adafruit_ble.uart import UARTServer |
| 12 | + |
| 13 | +from adafruit_ble import BLERadio |
| 14 | +from adafruit_ble.advertising.standard import ProvideServicesAdvertisement |
| 15 | +from adafruit_ble.services.nordic import UARTService |
13 | 16 |
|
14 | 17 | from adafruit_bluefruit_connect.packet import Packet |
15 | 18 | # Only the packet classes that are imported will be known to Packet. |
|
22 | 25 | blue_led.direction = digitalio.Direction.OUTPUT |
23 | 26 | red_led.direction = digitalio.Direction.OUTPUT |
24 | 27 |
|
25 | | -uart_server = UARTServer() |
| 28 | +ble = BLERadio() |
| 29 | +uart_service = UARTService() |
| 30 | +advertisement = ProvideServicesAdvertisement(uart_service) |
26 | 31 |
|
27 | 32 | # motor setup |
28 | 33 | motor_1 = crickit.dc_motor_1 |
|
46 | 51 | print("Use Adafruit Bluefruit app to connect") |
47 | 52 | while True: |
48 | 53 | blue_led.value = False |
49 | | - uart_server.start_advertising() |
50 | | - while not uart_server.connected: |
| 54 | + ble.start_advertising(advertisement) |
| 55 | + while not ble.connected: |
51 | 56 | # Wait for a connection. |
52 | 57 | pass |
53 | 58 | blue_led.value = True # turn on blue LED when connected |
54 | | - while uart_server.connected: |
55 | | - if uart_server.in_waiting: |
| 59 | + while ble.connected: |
| 60 | + if uart_service.in_waiting: |
56 | 61 | # Packet is arriving. |
57 | 62 | red_led.value = False # turn off red LED |
58 | | - packet = Packet.from_stream(uart_server) |
| 63 | + packet = Packet.from_stream(uart_service) |
59 | 64 | if isinstance(packet, ColorPacket): |
60 | 65 | # Change the color. |
61 | 66 | color = packet.color |
|
0 commit comments