-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz_button_token.py
More file actions
43 lines (34 loc) · 1.01 KB
/
z_button_token.py
File metadata and controls
43 lines (34 loc) · 1.01 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
import board
import time
import adafruit_dotstar
from digitalio import DigitalInOut, Direction, Pull
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
rgb = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
rgb.brightness = 0.3
red_button = DigitalInOut(board.D4)
red_button.direction = Direction.INPUT
red_button.pull = Pull.DOWN
yellow_button = DigitalInOut(board.D3)
yellow_button.direction = Direction.INPUT
yellow_button.pull = Pull.DOWN
def check(token):
if token == "RED":
return red_button.value
if token == "YELLOW":
return yellow_button.value
while True:
if check("RED"):
print("Red Button has been pressed")
else:
print("Red Button has not been pressed")
if check("YELLOW"):
print("Yellow Button has been pressed")
else:
print("Yellow Button has not been pressed")
led.value = check("RED")
if check("YELLOW"):
rgb[0] = (255, 255, 0)
else:
rgb[0] = (0, 0, 0)
time.sleep(0.2)