Adafruit_Learning_System_Gu.../lightbox/code.py
2019-11-24 20:55:51 -05:00

46 lines
1.2 KiB
Python

"""
Lightbox driver program.
Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!
Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.
All text above must be included in any redistribution.
"""
import board
import neopixel
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.color_packet import ColorPacket
pixel_pin = board.A0
num_pixels = 20
pixels = neopixel.NeoPixel(pixel_pin, num_pixels)
ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)
while True:
ble.start_advertising(advertisement)
while not ble.connected:
pass
# Now we're connected
while ble.connected:
if uart.in_waiting:
packet = Packet.from_stream(uart)
if isinstance(packet, ColorPacket):
# Change the NeoPixel color.
pixels.fill(packet.color)