-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttons.py
55 lines (49 loc) · 1.25 KB
/
buttons.py
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
54
55
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
redButton = 21
whiteButton = 20
blueButton = 16
GPIO.setup(redButton,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(whiteButton,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(blueButton,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
def allOff():
GPIO.output(22,GPIO.LOW)
GPIO.output(27,GPIO.LOW)
GPIO.output(17,GPIO.LOW)
buttonMode = 0
while(1):
if(GPIO.input(redButton)==GPIO.HIGH):
buttonMode = 0
time.sleep(.1)
print("red")
elif(GPIO.input(whiteButton)==GPIO.HIGH):
buttonMode =1
time.sleep(.1)
print("white")
elif(GPIO.input(blueButton)==GPIO.HIGH):
buttonMode=2
time.sleep(.1)
print("blue")
if buttonMode == 0:
allOff()
GPIO.output(22,1)
time.sleep(.10)
GPIO.output(22,0)
time.sleep(.10)
elif buttonMode == 1:
allOff()
GPIO.output(27,1)
time.sleep(.10)
GPIO.output(27,0)
time.sleep(.10)
elif buttonMode == 2:
allOff()
GPIO.output(17,1)
time.sleep(.10)
GPIO.output(17,0)
time.sleep(.10)