-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz_toggle_switch_neopixel_fill.py
More file actions
54 lines (43 loc) · 1.17 KB
/
z_toggle_switch_neopixel_fill.py
File metadata and controls
54 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import board
import time
from digitalio import DigitalInOut, Direction, Pull
import neopixel
pixel_pin = board.A2
num_pixels = 8
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.05, auto_write=False)
RED = (255, 0, 0)
ORANGE = (255, 128, 0)
YELLOW = (255, 255, 0)
BLACK = (0, 0, 0)
switchyellow = DigitalInOut(board.D3)
switchyellow.direction = Direction.INPUT
switchyellow.pull = Pull.DOWN
switchred = DigitalInOut(board.D4)
switchred.direction = Direction.INPUT
switchred.pull = Pull.DOWN
yellow_state = False
red_state = False
while True:
if switchred.value:
if red_state:
red_state = False
pixels.value = False
pixels.fill(BLACK)
pixels.show()
else:
red_state = True
pixels.value = True
pixels.fill(RED)
pixels.show()
if switchyellow.value:
if yellow_state:
yellow_state = False
pixels.value = False
pixels.fill(BLACK)
pixels.show()
else:
yellow_state = True
pixels.value = True
pixels.fill(YELLOW)
pixels.show()
time.sleep(0.3)