Created
May 12, 2022 22:46
-
-
Save lizzybrooks/b71952fb236fff5d93e9d4499b8abb49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# helper function for fading - do not touch | |
def fade(c1, c2): | |
diff = (c2[0]-c1[0], c2[1]-c1[1], c2[2]-c1[2]) | |
diffA = [1 if n==0 else abs(n) for n in diff] | |
maxDiff = max(diffA) | |
index = diffA.index(maxDiff) | |
cFade = list(c1) | |
increment = [int(diff[i]/diffA[i]) for i in range(3)] | |
for i in range(0, maxDiff): | |
for n in range(3): | |
if(cFade[n] != c2[n]): | |
cFade[n] += increment[n] | |
pixels.fill(tuple(cFade)) | |
pixels.show() | |
time.sleep(0.01) # debounce delay | |
if touch.raw_value < high_threshold and touch.raw_value > low_threshold: | |
break | |
def Tara(): | |
fade(OFF, YELLOW) | |
fade(YELLOW, GREEN) | |
time.sleep(0.5) # debounce delay | |
fade(GREEN, WHITE) | |
fade(WHITE, CYAN) | |
time.sleep(0.5) # debounce delay | |
fade(CYAN, BLUE) | |
fade(BLUE, PURPLE) | |
time.sleep(0.5) # debounce delay | |
fade(PURPLE, PURPLE) | |
fade(PURPLE, OFF) | |
time.sleep(0.5) # debounce delay)# Write your code here :-) | |
#end helper function | |
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") | |
Tara() | |
if (now==1): | |
print("do something for 1") | |
pixels.fill(OFF) | |
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