To use with CircuitPython, you need to first install a few libraries, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.

Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the .STL file, the necessary libraries, and the code.py file in a zip file. Extract the contents of the zip file, open the directory NeoPixel_Frankenstein/ and then click on the directory that matches the version of CircuitPython you're using and copy code.py and the lib/ directory to your CIRCUITPY drive.

Your CIRCUITPY drive should now look similar to the following image:

CIRCUITPY
# SPDX-FileCopyrightText: 2020 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
import touchio
import neopixel
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.color import (
    RED,
    YELLOW,
    ORANGE,
    GREEN,
    TEAL,
    CYAN,
    BLUE,
    PURPLE,
    MAGENTA,
    GOLD,
    PINK,
    AQUA,
    JADE,
    AMBER
)

#  NeoPixel pin
pixel_pin = board.A3
#  number of NeoPixels
pixel_num = 68

#  NeoPixels setup
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

#  animation setup
pulse = Pulse(pixels, speed=0.1, color=RED, period=5)

#  two cap touch pins
touch_left = board.A1
touch_right = board.A2

#  cap touch setup
bolt_left = touchio.TouchIn(touch_left)
bolt_right = touchio.TouchIn(touch_right)

#  NeoPixel colors for animation
colors = [RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, BLUE,
          PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER]

#  variable for color array index
c = 0

#  debounce states for cap touch
bolt_left_state = False
bolt_right_state = False

while True:
    #  run animation
    pulse.animate()

    #  debounce for cap touch
    if not bolt_left.value and not bolt_left_state:
        bolt_left_state = True
    if not bolt_right.value and not bolt_right_state:
        bolt_right_state = True

    #  if the left bolt is touched...
    if bolt_left.value and bolt_left_state:
        print("Touched left bolt!")
        #  increase color array index by 1
        c += 1
        #  reset debounce state
        bolt_left_state = False
    #  if the right bolt is touched...
    if bolt_right.value and bolt_right_state:
        print("Touched right bolt!")
        #  decrease color array index by 1
        c -= 1
        #  reset debounce state
        bolt_right_state = False
    #  if the color array index is bigger than 13...
    if c > 13:
        #  reset it to 0
        c = 0
    #  if the color array index is smaller than 0...
    if c < 0:
        #  reset it to 13
        c = 13
    #  update animation color to current array index
    pulse.color = colors[c]
    time.sleep(0.01)
You'll need to solder the 2MB SPI flash to the QT Py to run the code as written.

This guide was first published on Oct 27, 2020. It was last updated on Oct 27, 2020.

This page (Coding the NeoPixel Frankenstein) was last updated on May 26, 2023.

Text editor powered by tinymce.