-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserIO.py
More file actions
116 lines (99 loc) · 4.44 KB
/
userIO.py
File metadata and controls
116 lines (99 loc) · 4.44 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import RPi.GPIO as GPIO
from time import sleep
class uIO:
def __init__(self, ct):
self.colorList = []
self.ct = ct
def updateCategory(self):
done = False
while not done:
print 'If done, type "done"'
color = raw_input('Enter the lowercase color you would like to change:\n')
if color == 'done' or color == '':
done = True
elif not(color == 'red') and not(color == 'blue') and not(color == 'white') and not(color == 'green') and not(color == 'yellow'):
print '\nPlease enter a valid color\n'
else:
prompt = 'What category will be assigned to ' + color + ':\n'
cat = raw_input(prompt)
if color == 'red':
self.ct.red.setCategory(cat)
elif color == 'blue':
self.ct.blue.setCategory(cat)
elif color == 'white':
self.ct.white.setCategory(cat)
elif color == 'green':
self.ct.green.setCategory(cat)
elif color == 'yellow':
self.ct.yellow.setCategory(cat)
class rpiIO:
def __init__(self):
self.inputDelay = 0.1
self.sleepTime = 0.5
# LEDs
self.redLed, self.blueLed, self.whiteLed, self.greenLed, self.yellowLed = 4, 17, 27, 22, 24
self.leds = [self.redLed, self.blueLed, self.whiteLed, self.greenLed, self.yellowLed]
# Buttons
self.buttonPin1, self.buttonPin2, self.buttonPin3, self.buttonPin4, self.buttonPin5, self.buttonPin6 = 5, 6, 13, 19, 26, 16
self.buttons = [self.buttonPin1, self.buttonPin2, self.buttonPin3, self.buttonPin4, self.buttonPin5, self.buttonPin6]
#Dict of buttons --> LEDs
self.buttonsToLeds = {self.buttonPin1:self.redLed, self.buttonPin2:self.blueLed, self.buttonPin3:self.whiteLed, self.buttonPin4:self.greenLed, self.buttonPin5:self.yellowLed}
# Setup LED and Button pins
def setupPins(self):
GPIO.setmode(GPIO.BCM)
for led in self.leds:
GPIO.setup(led, GPIO.OUT)
for button in self.buttons:
GPIO.setup(button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
return
# Power off LEDS and clean up GPIO
def cleanUp(self):
for led in self.leds:
GPIO.output(led, GPIO.LOW)
GPIO.cleanup()
return
def ledSleep(self):
sleep(self.sleepTime)
return
def ledBlink(self, pin):
GPIO.output(self.buttonsToLeds[pin], GPIO.HIGH)
self.ledSleep()
GPIO.output(self.buttonsToLeds[pin], GPIO.LOW)
self.ledSleep()
def otherPinPressed(self, pin):
if pin == self.buttonPin1: #red
if not GPIO.input(self.buttonPin6):
return -1
elif GPIO.input(self.buttonPin2) and GPIO.input(self.buttonPin3) and GPIO.input(self.buttonPin4) and GPIO.input(self.buttonPin5):
return 0
else:
return 1
elif pin == self.buttonPin2: #blue
if not GPIO.input(self.buttonPin6):
return -1
elif GPIO.input(self.buttonPin1) and GPIO.input(self.buttonPin3) and GPIO.input(self.buttonPin4) and GPIO.input(self.buttonPin5):
return 0
else:
return 1
elif pin == self.buttonPin3: #white
if not GPIO.input(self.buttonPin6):
return -1
elif GPIO.input(self.buttonPin1) and GPIO.input(self.buttonPin2) and GPIO.input(self.buttonPin4) and GPIO.input(self.buttonPin5):
return 0
else:
return 1
elif pin == self.buttonPin4:#green
if not GPIO.input(self.buttonPin6):
return -1
elif GPIO.input(self.buttonPin1) and GPIO.input(self.buttonPin2) and GPIO.input(self.buttonPin3) and GPIO.input(self.buttonPin5):
return 0
else:
return 1
elif pin == self.buttonPin5: #yellow
if not GPIO.input(self.buttonPin6):
return -1
elif GPIO.input(self.buttonPin1) and GPIO.input(self.buttonPin2) and GPIO.input(self.buttonPin3) and GPIO.input(self.buttonPin4):
return 0
else:
return 1
# end IO