|
1 | 1 | # Circuit Playground Bluefruit Rover |
2 | 2 | # Use with the Adafruit BlueFruit LE Connect app |
3 | | -# Works with CircuitPython 4.0.0-beta.1 and later |
| 3 | +# Works with CircuitPython 5.0.0-beta.0 and later |
4 | 4 | # running on an nRF52840 CPB board and Crickit |
5 | 5 |
|
6 | 6 | import time |
7 | 7 | import board |
8 | 8 | import digitalio |
9 | 9 | import neopixel |
10 | 10 | from adafruit_crickit import crickit |
11 | | -from adafruit_ble.uart_server import UARTServer |
| 11 | + |
| 12 | +from adafruit_ble import BLERadio |
| 13 | +from adafruit_ble.advertising.standard import ProvideServicesAdvertisement |
| 14 | +from adafruit_ble.services.nordic import UARTService |
12 | 15 |
|
13 | 16 | from adafruit_bluefruit_connect.packet import Packet |
14 | 17 | # Only the packet classes that are imported will be known to Packet. |
|
19 | 22 | red_led = digitalio.DigitalInOut(board.D13) |
20 | 23 | red_led.direction = digitalio.Direction.OUTPUT |
21 | 24 |
|
22 | | -uart_server = UARTServer() |
| 25 | +ble = BLERadio() |
| 26 | +uart_service = UARTService() |
| 27 | +advertisement = ProvideServicesAdvertisement(uart_service) |
23 | 28 |
|
24 | 29 | # motor setup |
25 | 30 | motor_1 = crickit.dc_motor_1 |
|
42 | 47 | print("BLE Turtle Rover") |
43 | 48 | print("Use Adafruit Bluefruit app to connect") |
44 | 49 | while True: |
45 | | - # blue_led.value = False |
46 | 50 | neopixels[0] = BLACK |
47 | 51 | neopixels.show() |
48 | | - uart_server.start_advertising() |
49 | | - while not uart_server.connected: |
| 52 | + ble.start_advertising(advertisement) |
| 53 | + while not ble.connected: |
50 | 54 | # Wait for a connection. |
51 | 55 | pass |
52 | 56 | # set a pixel blue when connected |
53 | 57 | neopixels[0] = BLUE |
54 | 58 | neopixels.show() |
55 | | - while uart_server.connected: |
56 | | - if uart_server.in_waiting: |
| 59 | + while ble.connected: |
| 60 | + if uart_service.in_waiting: |
57 | 61 | # Packet is arriving. |
58 | 62 | red_led.value = False # turn off red LED |
59 | | - packet = Packet.from_stream(uart_server) |
| 63 | + packet = Packet.from_stream(uart_service) |
60 | 64 | if isinstance(packet, ColorPacket): |
61 | 65 | # Change the color. |
62 | 66 | color = packet.color |
|
0 commit comments