You can connect any type of NeoPixels to the NeoPixel port on the Crickit for Circuit Playground Express. Be sure you connect the Power and Ground connections appropriately.
The center arrow terminal on Crickit NeoPixel block is connected to Din on the first NeoPixel or the beginning of a strip of NeoPixels.
Likewise the Crickit Feather WIng has the same NeoPixel block.
The board is just rotated a bit from the above picture, same location).
Using NeoPixels in your Crickit project is easy and fun, providing a dedicated port on the Crickit to directly wire 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.
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)
.
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries # # SPDX-License-Identifier: MIT # Drive NeoPixels on the NeoPixels Block on Crickit for # Circuit Playground Express import time from rainbowio import colorwheel 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 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 pixels[i] = colorwheel(rc_index & 255) pixels.show() time.sleep(wait) RED = (255, 0, 0) YELLOW = (255, 150, 0) GREEN = (0, 255, 0) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) while True: print("fill") pixels.fill(RED) pixels.show() # Increase or decrease to change the speed of the solid color change. time.sleep(1) pixels.fill(GREEN) pixels.show() time.sleep(1) pixels.fill(BLUE) pixels.show() time.sleep(1) print("chase") color_chase(RED, 0.1) # Increase the number to slow down the color chase color_chase(YELLOW, 0.1) color_chase(GREEN, 0.1) color_chase(CYAN, 0.1) color_chase(BLUE, 0.1) color_chase(PURPLE, 0.1) print("rainbow") rainbow_cycle(0) # Increase the number to slow down the rainbow
The NeoPixel block signal wire is connected to the Crickit Seesaw control chip pin #20. The following code sets up an external 30 NeoPixel strip connected to the Crickit FeatherWing or HAT
On Raspberry Pi, you'll also need to add the library: from your command line run the following command:
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries # # SPDX-License-Identifier: MIT # Drive NeoPixels on the NeoPixels Block on Crickit FeatherWing import time from rainbowio import colorwheel from adafruit_crickit import crickit from adafruit_seesaw.neopixel import NeoPixel num_pixels = 30 # Number of pixels driven from Crickit NeoPixel terminal # The following line sets up a NeoPixel strip on Seesaw pin 20 for Feather pixels = NeoPixel(crickit.seesaw, 20, num_pixels) 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 pixels[i] = colorwheel(rc_index & 255) pixels.show() time.sleep(wait) RED = (255, 0, 0) YELLOW = (255, 150, 0) GREEN = (0, 255, 0) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) while True: print("fill") pixels.fill(RED) pixels.show() # Increase or decrease to change the speed of the solid color change. time.sleep(1) pixels.fill(GREEN) pixels.show() time.sleep(1) pixels.fill(BLUE) pixels.show() time.sleep(1) print("chase") color_chase(RED, 0.1) # Increase the number to slow down the color chase color_chase(YELLOW, 0.1) color_chase(GREEN, 0.1) color_chase(CYAN, 0.1) color_chase(BLUE, 0.1) color_chase(PURPLE, 0.1) print("rainbow") rainbow_cycle(0) # Increase the number to slow down the rainbow
Currently the micro:bit is not supported in CircuitPython. The micro:bit is programmable in MicroPython but there is no Crickit drive support for MicroPython at present.
For More Information
See the tutorial Make It Glow with Crickit.
Text editor powered by tinymce.