The Bluefruit LE Connect app has a Color Picker that allows you to easily set the color of NeoPixels connected to your Adafruit nRF52840. For this demo, we'll change the color of the on-board NeoPIxel using CircuitPython and the Bluefruit LE Connect app.
Save the following as code.py on your CIRCUITPY
drive and then connect to the board using the Bluefruit LE Connect app.
Drag the library files from the library bundle to the lib folder on your CIRUCUITPY drive.
# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # CircuitPython NeoPixel Color Picker Example import board import neopixel from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.color_packet import ColorPacket from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService ble = BLERadio() uart_service = UARTService() advertisement = ProvideServicesAdvertisement(uart_service) pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1) while True: # Advertise when not connected. ble.start_advertising(advertisement) while not ble.connected: pass ble.stop_advertising() while ble.connected: if uart_service.in_waiting: packet = Packet.from_stream(uart_service) if isinstance(packet, ColorPacket): print(packet.color) pixels.fill(packet.color)
Connect to your board using the Bluefruit LE Connect application and navigate to the Color Picker page.
Let's take a look at the code.
First we import the necessary libraries and instantiate the UART server.
Inside the loop, we first begin advertising.
Once connected, the board begins listening for packets. In the event that a color packet is received, it changes the color of the NeoPixel to the chosen color.
Now you can use the color picker to change the color and send that color to the NeoPixel.
That's all there is to changing the color of NeoPixels with the Bluefruit LE Connect app and CircuitPython! You can easily attach external NeoPixels and change the color with the app as well. Check it out!
Text editor powered by tinymce.