The application comes with a small sample program which will spin a colorful circle around the NeoPixels on the board.
In order to interact with the NeoPixels, the sample code makes use of the adafruit_circuitplayground
library.
If you haven't already installed the Adafruit libraries onto your Circuit Playground Express board, you can learn about installing the adafruit_circuitplayground
library in the CircuitPython Essentials Guide on CircuitPlayground Libraries. It is easiest to install the whole library package if you do not plan to use the flash space on the board for other files.
Here is the sample script:
from adafruit_circuitplayground.express import cpx import time # Change the color here. color = (0,0,255) # Change the delay here. The lower the delay value the faster the animation. delay = 50 pixels = cpx.pixels pixels.brightness = 0.05 pixels.fill((0, 0, 0)) pixels.show() while True: for i in range(0, len(pixels)): pixels[i] = color time.sleep(delay * 1/1000) for i in range(0, len(pixels)): pixels[i] = (0,0,0) time.sleep(delay * 1/1000)
When you are ready, press the SAVE button. This will save the sample script from the code editor into the code.py file on your board. If there is anything important in your code.py file, please keep a backup on your computer.
Swipe back to the serial terminal page. Once the saving is complete, press the CTRL-D button to restart the board and execute code.py.
Your board's NeoPixels should animate with a blue circle. If that is working properly, then go ahead and swipe back to the code editor and make a change to the color
variable in the code on line 5:
color = (0,0,255)
The 3 values there represent the RGB values that the NeoPixels will get set to. You could change them to (0,255,0)
for green, or choose any other color combination you like. If you haven't learned about using the NeoPixels with CircuitPython yet, check out the guide here.
Once you are ready press the SAVE button to save the code back to the boards code.py file. Then swipe back again and press the CTRL-D button to restart the board and execute code.py again you should now see whatever color you chose. Feel free to edit other aspects of the code, another easy one to play with is the delay
variable.
Page last edited March 08, 2024
Text editor powered by tinymce.