Created
April 7, 2023 21:46
-
-
Save lizzybrooks/3948c4a8f8bdbff618fbed4f6af61cde 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 | |
switch = DigitalInOut(board.D3) | |
switch.direction = Direction.INPUT | |
switch.pull = Pull.UP | |
pixel_pin = board.D2 | |
num_pixels = 16 | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False) | |
press_count=0 | |
OFF = (0,0,0) | |
DRACONICBLUE = (20,0,255) | |
DRACONICCYAN = (12,240,240) | |
DRACONICGREEN = (60, 215, 10) | |
DRACONICLIME = (185,240,50) | |
def press_check(): | |
global press_count | |
if (switch.value==False): | |
press_count+=1 | |
if press_count>2: | |
press_count=0 | |
time.sleep(0.2) | |
print(press_count) | |
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 | |
global press_count | |
if (switch.value==False): | |
press_count+=1 | |
if press_count>2: | |
press_count=0 | |
time.sleep(0.2) | |
break | |
print(press_count) | |
while True: | |
press_check() | |
if press_count==0: | |
pixels.fill(DRACONICLIME) | |
pixels.show() | |
if press_count==1: | |
fade(DRACONICBLUE, DRACONICCYAN) | |
fade(DRACONICCYAN, DRACONICGREEN) | |
fade(DRACONICGREEN, DRACONICLIME) | |
fade(DRACONICLIME, DRACONICGREEN) | |
fade(DRACONICGREEN, DRACONICCYAN) | |
fade(DRACONICCYAN, DRACONICBLUE) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment