Skip to content

Instantly share code, notes, and snippets.

@clairebassett28
Created February 6, 2025 19:38
Show Gist options
  • Save clairebassett28/89879973a2e7525fc13aee84f84e0408 to your computer and use it in GitHub Desktop.
Save clairebassett28/89879973a2e7525fc13aee84f84e0408 to your computer and use it in GitHub Desktop.
Using a touch sensitive wire to change colors.
import time
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
import touchio
touch_pad = board.A0 # the ~1 pin
touch = touchio.TouchIn(touch_pad)
pixel_pin = board.D2
num_pixels = 16
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
OFF = (0, 0, 0)
colors = [RED,YELLOW,GREEN,CYAN,BLUE,PURPLE,WHITE,OFF]
now = 0
while True:
if touch.value:
now = now + 1
if (now >= len(colors)): #check to see if we exceed our list of colors
now = 0
pixels.fill(colors[now])
pixels.show()
time.sleep(0.1) # debounce delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment