Skip to content

Commit f2d024c

Browse files
committed
Update to new BLE API; add SPEAKER_ENABLE
1 parent 8fced95 commit f2d024c

File tree

1 file changed

+18
-7
lines changed
  • Circuit_Playground_Bluefruit_Pumpkin

1 file changed

+18
-7
lines changed

Circuit_Playground_Bluefruit_Pumpkin/code.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
import time
55
import board
6+
import digitalio
67
import neopixel
7-
from adafruit_ble.uart_server import UARTServer
8+
9+
from adafruit_ble import BLERadio
10+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
11+
from adafruit_ble.services.nordic import UARTService
12+
813
from audiopwmio import PWMAudioOut as AudioOut
914
from audiocore import WaveFile
1015

@@ -24,9 +29,15 @@
2429
YELLOW = (255,230, 0)
2530
BLUE = (0, 0, 255)
2631
# setup bluetooth
27-
uart_server = UARTServer()
32+
ble = BLERadio()
33+
uart_service = UARTService()
34+
advertisement = ProvideServicesAdvertisement(uart_service)
2835

2936
# External Audio Stuff
37+
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
38+
speaker_enable.direction = digitalio.Direction.OUTPUT
39+
speaker_enable.value = True
40+
3041
audio = AudioOut(board.SPEAKER) # Speaker
3142
wave_file = None
3243

@@ -51,17 +62,17 @@ def play_wav(name, loop=False):
5162

5263
while True:
5364
# set CPXb up so that it can be discovered by the app
54-
uart_server.start_advertising()
55-
while not uart_server.connected:
65+
ble.start_advertising(advertisement)
66+
while not ble.connected:
5667
pass
5768

5869
# Now we're connected
5970

60-
while uart_server.connected:
71+
while ble.connected:
6172

62-
if uart_server.in_waiting:
73+
if uart_service.in_waiting:
6374
try:
64-
packet = Packet.from_stream(uart_server)
75+
packet = Packet.from_stream(uart_service)
6576
except ValueError:
6677
continue # or pass.
6778

0 commit comments

Comments
 (0)