-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson2_four_buttons_dotstar.py
More file actions
41 lines (35 loc) · 1.05 KB
/
lesson2_four_buttons_dotstar.py
File metadata and controls
41 lines (35 loc) · 1.05 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
import board
import time
from digitalio import DigitalInOut, Direction, Pull
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
led.brightness = 0.1
switchyellow = DigitalInOut(board.D1)
switchyellow.direction = Direction.INPUT
switchyellow.pull = Pull.DOWN
switchorange = DigitalInOut(board.D2)
switchorange.direction = Direction.INPUT
switchorange.pull = Pull.DOWN
switchblue = DigitalInOut(board.D3)
switchblue.direction = Direction.INPUT
switchblue.pull = Pull.DOWN
switchgreen = DigitalInOut(board.D4)
switchgreen.direction = Direction.INPUT
switchgreen.pull = Pull.DOWN
while True:
if switchyellow.value:
led.value = True
led[0] = (255, 0, 0)
elif switchorange.value:
led.value = True
led[0] = (0, 255, 0)
elif switchblue.value:
led.value = True
led[0] = (0, 0, 255)
elif switchgreen.value:
led.value = True
led[0] = (255, 255, 255)
else:
led.value = False
led[0] = (0, 0, 0)
time.sleep(0.01) # debounce delay