Skip to content

Commit 3f4a26c

Browse files
authored
Merge pull request adafruit#951 from dhalbert/cpy5beta0-cpb-turtle-rover
Update CPB Rover to CircuitPython 5.0.0-beta.0 BLE API
2 parents dfb7cfc + 8532a0a commit 3f4a26c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Turtle_BLE_CPB_Crickit_Rover/turtle_ble_cpb_crickit_rover.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Circuit Playground Bluefruit Rover
22
# 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
44
# running on an nRF52840 CPB board and Crickit
55

66
import time
77
import board
88
import digitalio
99
import neopixel
1010
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
1215

1316
from adafruit_bluefruit_connect.packet import Packet
1417
# Only the packet classes that are imported will be known to Packet.
@@ -19,7 +22,9 @@
1922
red_led = digitalio.DigitalInOut(board.D13)
2023
red_led.direction = digitalio.Direction.OUTPUT
2124

22-
uart_server = UARTServer()
25+
ble = BLERadio()
26+
uart_service = UARTService()
27+
advertisement = ProvideServicesAdvertisement(uart_service)
2328

2429
# motor setup
2530
motor_1 = crickit.dc_motor_1
@@ -42,21 +47,20 @@
4247
print("BLE Turtle Rover")
4348
print("Use Adafruit Bluefruit app to connect")
4449
while True:
45-
# blue_led.value = False
4650
neopixels[0] = BLACK
4751
neopixels.show()
48-
uart_server.start_advertising()
49-
while not uart_server.connected:
52+
ble.start_advertising(advertisement)
53+
while not ble.connected:
5054
# Wait for a connection.
5155
pass
5256
# set a pixel blue when connected
5357
neopixels[0] = BLUE
5458
neopixels.show()
55-
while uart_server.connected:
56-
if uart_server.in_waiting:
59+
while ble.connected:
60+
if uart_service.in_waiting:
5761
# Packet is arriving.
5862
red_led.value = False # turn off red LED
59-
packet = Packet.from_stream(uart_server)
63+
packet = Packet.from_stream(uart_service)
6064
if isinstance(packet, ColorPacket):
6165
# Change the color.
6266
color = packet.color

0 commit comments

Comments
 (0)