Skip to content

Instantly share code, notes, and snippets.

@lizzybrooks
Created May 12, 2022 22:38
Show Gist options
  • Save lizzybrooks/2b9bb1e00384a32270d92a96a4829d3c to your computer and use it in GitHub Desktop.
Save lizzybrooks/2b9bb1e00384a32270d92a96a4829d3c to your computer and use it in GitHub Desktop.
import time
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
import touchio
touch_pad = board.A0 # the ~1 pin
high_threshold = 4059
low_threshold = 3500
touch = touchio.TouchIn(touch_pad)
pixel_pin = board.D2
num_pixels = 12
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
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)
now=0
while True:
if touch.raw_value < high_threshold and touch.raw_value > low_threshold:
print(now)
if (now ==0):
print("do something for zero")
pixels.fill(YELLOW)
pixels.show()
if (now==1):
print("do something for 1")
pixels.fill(CYAN)
pixels.show()
now = now +1
if (now > 1) :
now=0
time.sleep(.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment