Skip to content

Commit 53e27bf

Browse files
committed
Add lightbox code
1 parent db5bbad commit 53e27bf

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

lightbox/code.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Lightbox driver program.
3+
4+
Adafruit invests time and resources providing this open source code.
5+
Please support Adafruit and open source hardware by purchasing
6+
products from Adafruit!
7+
8+
Written by Dave Astels for Adafruit Industries
9+
Copyright (c) 2018 Adafruit Industries
10+
Licensed under the MIT license.
11+
12+
All text above must be included in any redistribution.
13+
"""
14+
15+
import board
16+
import neopixel
17+
from adafruit_ble.uart import UARTServer
18+
from adafruit_bluefruit_connect.packet import Packet
19+
from adafruit_bluefruit_connect.color_packet import ColorPacket
20+
21+
pixel_pin = board.A0
22+
num_pixels = 20
23+
24+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels)
25+
26+
uart_server = UARTServer()
27+
28+
while True:
29+
uart_server.start_advertising()
30+
while not uart_server.connected:
31+
pass
32+
33+
# Now we're connected
34+
35+
while uart_server.connected:
36+
if uart_server.in_waiting:
37+
packet = Packet.from_stream(uart_server)
38+
if isinstance(packet, ColorPacket):
39+
# Change the NeoPixel color.
40+
pixels.fill(packet.color)

0 commit comments

Comments
 (0)