Created
May 6, 2022 22:37
-
-
Save RajanRao12/5c2e0f6965b20f2e3bbf7b005f8a55d6 to your computer and use it in GitHub Desktop.
Organic Light pattern with switch (doesn't work)
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 | |
pixel_pin = board.D2 | |
num_pixels = 12 | |
switch = DigitalInOut(board.D3) | |
switch.direction = Direction.INPUT | |
switch.pull = Pull.UP | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.5, auto_write=False) | |
ROBIN = (222,35,5) | |
ROBINDIM = (111,18,3) | |
ROBINDIMMER = (56,12,2) | |
ROBINDIMMEST = (28,6,1) | |
OFF = (0,0,0) | |
press_count=0 | |
def press_check(): | |
global press_count | |
if (switch.value==False): | |
press_count+=1 | |
if press_count>2: | |
press_count=0 | |
time.sleep(0.3) | |
print(press_count) | |
while True: | |
print(switch.value) | |
if (switch.value==True): | |
for i in range(0,12,1): | |
pixels[i]=OFF | |
pixels.show() | |
time.sleep(0.1) | |
pixels[i-1]=ROBINDIMMEST | |
pixels.show() | |
time.sleep(0.1) | |
if (switch.value==False): | |
pixels.fill(OFF) | |
pixels.show() | |
pixels[i-2]=ROBINDIMMER | |
pixels.show() | |
time.sleep(0.1) | |
pixels[i-3]=ROBINDIM | |
pixels.show() | |
time.sleep(0.1) | |
pixels[i-4]=ROBIN | |
pixels.show() | |
time.sleep(0.1) | |
else: | |
pixels.fill(OFF) | |
pixels.show() | |
time.sleep(1) # debounce delay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment