Skip to content

Commit 4e7293f

Browse files
committed
update for CircuitPython 5.0.0-beta.0 BLE API
1 parent 8fced95 commit 4e7293f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

BLE_Crickit_Light_Switch/ble_crickit_light_switch.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BLE Crickit Light Switch
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 Feather board and Crickit FeatherWing
55
# micro servo, 3D printed switch actuator
66

@@ -10,7 +10,10 @@
1010
import digitalio
1111

1212
from adafruit_crickit import crickit
13-
from adafruit_ble.uart import UARTServer
13+
14+
from adafruit_ble import BLERadio
15+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
16+
from adafruit_ble.services.nordic import UARTService
1417

1518
from adafruit_bluefruit_connect.packet import Packet
1619
# Only the packet classes that are imported will be known to Packet.
@@ -22,7 +25,9 @@
2225
blue_led.direction = digitalio.Direction.OUTPUT
2326
red_led.direction = digitalio.Direction.OUTPUT
2427

25-
uart_server = UARTServer()
28+
ble = BLERadio()
29+
uart_service = UARTService()
30+
advertisement = ProvideServicesAdvertisement(uart_service)
2631

2732
UP_ANGLE = 180
2833
NEUTRAL_ANGLE = 120
@@ -35,17 +40,17 @@
3540
print("Use Adafruit Bluefruit app to connect")
3641
while True:
3742
blue_led.value = False
38-
uart_server.start_advertising()
43+
ble.start_advertising(advertisement)
3944

40-
while not uart_server.connected:
45+
while not ble.connected:
4146
# Wait for a connection.
4247
pass
4348
blue_led.value = True # turn on blue LED when connected
44-
while uart_server.connected:
45-
if uart_server.in_waiting:
49+
while ble.connected:
50+
if uart_service.in_waiting:
4651
# Packet is arriving.
4752
red_led.value = False # turn off red LED
48-
packet = Packet.from_stream(uart_server)
53+
packet = Packet.from_stream(uart_service)
4954
if isinstance(packet, ButtonPacket) and packet.pressed:
5055
red_led.value = True # blink to show a packet has been received
5156
if packet.button == ButtonPacket.UP and angle != UP_ANGLE: # UP button pressed

0 commit comments

Comments
 (0)