Skip to content

update NeoPixel_Badge_Lanyard BLE code #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions NeoPixel_Badge_Lanyard/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import board
import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy
from adafruit_ble.uart import UARTServer
# for >= CPy 5.0.0
# from adafruit_ble.uart_server import UARTServer

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.button_packet import ButtonPacket
from adafruit_bluefruit_connect.color_packet import ColorPacket
Expand Down Expand Up @@ -54,7 +56,9 @@
offset_increment = 1
OFFSET_MAX = 1000000

uart_server = UARTServer()
ble = BLERadio()
uart_service = UARTService()
advertisement = ProvideServicesAdvertisement(uart_service)

def set_palette(palette):
for i in range(NUM_LEDS):
Expand All @@ -72,17 +76,19 @@ def set_palette(palette):
cycling = True

while True:
uart_server.start_advertising()
while not uart_server.connected:
# Advertise when not connected.
ble.start_advertising(advertisement)

while not ble.connected:
if cycling:
set_palette(palette_choice)
offset = (offset + offset_increment) % OFFSET_MAX

# Now we're connected

while uart_server.connected:
if uart_server.in_waiting:
packet = Packet.from_stream(uart_server)
while ble.connected:
if uart_service.in_waiting:
packet = Packet.from_stream(uart_service)
if isinstance(packet, ColorPacket):
cycling = False
# Set all the pixels to one color and stay there.
Expand Down