User Manual

NeoPixels easily.
The sample code for using NeoPixels on the Crickit vary slightly depending on which version of Crickit you have. Look
for the appropriate section on this page for your combination of Crickit and microcontroller.
NeoPixels with Circuit Playground Express + Crickit
The NeoPixel terminal block is controlled by the Circuit Playground Express pad A1. The pad A1 definition is obtained
by import board . Then the NeoPixel routine is from import neopixel .
Various animations are provided by def ined functions wheel , color_chase and rainbow_cycle . Various solid colors
are then defined, you are free to use whichever colors you wish.
You can define a new color variable as a Python tuple with three values for red, green, blue, for example WHITE =
(255, 255, 255) .
If you are looking to use the NeoPixels on the Circuit Playground Express board itself, Adafruit has several
tutorials that program them with CircuitPython. See Make It Glow with Crickit for details.
# Drive NeoPixels on the NeoPixels Block on Crickit for
# Circuit Playground Express
import time
import neopixel
import board
num_pixels = 30 # Number of pixels driven from Crickit NeoPixel terminal
# The following line sets up a NeoPixel strip on Crickit CPX pin A1
pixels = neopixel.NeoPixel(board.A1, num_pixels, brightness=0.3,
auto_write=False)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
def color_chase(color, wait):
for i in range(num_pixels):
pixels[i] = color
time.sleep(wait)
pixels.show()
time.sleep(0.5)
def rainbow_cycle(wait):
for j in range(255):
for i in range(num_pixels):
rc_index = (i * 256 // num_pixels) + j
© Adafruit Industries
https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-
construction-kit
Page 119 of 201