-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event_Pullup.py
executable file
·223 lines (168 loc) · 7.76 KB
/
Event_Pullup.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#Python 3.6.8 (default, Jan 14 2019, 11:02:34)
#[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
#Type "help", "copyright", "credits" or "license()" for more information.
#!/usr/bin/Python3
import time
import os
import RPi.GPIO as GPIO
import sys
GPIO.setmode(GPIO.BCM)
DEBUG=1 #To see debug warnings set to "1" otherwise "0"
Btime=500 # This sets the debounce time in milliseconds.
northButton=4
powerButton=14
westButton=15
southButton=18
eastButton=23
GPIO.setup(powerButton,GPIO.IN,pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(powerButton, GPIO.FALLING, bouncetime=Btime) # GPIO might need to be switched to RISING to prevent bounceing.
GPIO.setup(northButton,GPIO.IN,pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(northButton, GPIO.FALLING, bouncetime=Btime)
GPIO.setup(westButton,GPIO.IN,pull_up_down = GPIO.PUD_UP)
WEST = GPIO.add_event_detect(westButton, GPIO.FALLING, bouncetime=Btime)
GPIO.setup(southButton,GPIO.IN,pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(southButton, GPIO.FALLING, bouncetime=Btime)
GPIO.setup(eastButton,GPIO.IN,pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(eastButton, GPIO.FALLING, bouncetime=Btime)
def zeroMode():
if GPIO.event_detected(northButton):
if(DEBUG):print("North button accidentally pressed")
if GPIO.event_detected(westButton):
if(DEBUG):print("West button accidentally pressed")
if GPIO.event_detected(eastButton):
if(DEBUG):print("East button accidentally pressed")
if GPIO.event_detected(southButton):
if(DEBUG):print("South button accidentally pressed")
if GPIO.event_detected(powerButton):
if(DEBUG):print("Power button accidentally pressed")
def cable():
while True:
if GPIO.event_detected(northButton):
print("Motor 3 selected in cable mode.")
motor3_spin()
if GPIO.event_detected(westButton):
print("Motor 1 selected in cable mode.")
motor1_spin()
if GPIO.event_detected(southButton):
print("Motor 2 selected in cable mode.")
motor2_spin()
if GPIO.event_detected(eastButton):
print("Motor 4 selected in cable mode.")
motor4_spin()
if GPIO.event_detected(powerButton):
print("Exiting cable.")
os.system('/home/pi/Ridiculous/vibrate.sh') # Effector movement to signal user of exit.
main()
def motor1_spin():
while True:
if GPIO.event_detected(northButton):
print("void")
if GPIO.event_detected(westButton):
print("Motor 1 clock.")
os.system('/home/pi/Ridiculous/1_cw.sh')
if GPIO.event_detected(southButton):
print("void")
if GPIO.event_detected(eastButton):
print("Motor 1 counter.")
os.system('/home/pi/Ridiculous/1_ccw.sh')
if GPIO.event_detected(powerButton):
print("cable")
cable()
def motor2_spin():
while True:
if GPIO.event_detected(northButton):
print("void")
if GPIO.event_detected(westButton):
print("Motor 2 clock.")
os.system('/home/pi/Ridiculous/2_ccw.sh')
if GPIO.event_detected(southButton):
print("void")
if GPIO.event_detected(eastButton):
print("Motor 2 counter.")
os.system('/home/pi/Ridiculous/2_cw.sh')
if GPIO.event_detected(powerButton):
print("cable")
cable()
def motor3_spin():
while True:
if GPIO.event_detected(northButton):
print("void")
if GPIO.event_detected(westButton):
print("Motor 3 clock.")
os.system('/home/pi/Ridiculous/3_cw.sh')
if GPIO.event_detected(southButton):
print("void")
if GPIO.event_detected(eastButton):
print("Motor 3 counter.")
os.system('/home/pi/Ridiculous/3_ccw.sh')
if GPIO.event_detected(powerButton):
print("cable")
cable()
def motor4_spin():
while True:
if GPIO.event_detected(northButton):
print("void")
if GPIO.event_detected(westButton):
print("Motor 4 clock.")
os.system('/home/pi/Ridiculous/4_cw.sh')
if GPIO.event_detected(southButton):
print("void")
if GPIO.event_detected(eastButton):
print("Motor 4 counter.")
os.system('/home/pi/Ridiculous/4_ccw.sh')
if GPIO.event_detected(powerButton):
print("cable")
cable()
def boo():
if GPIO.event_detected(powerButton):
if(DEBUG):print("Wait 2 seconds")
time.sleep (2) #After button press wait 2 seconds
if GPIO.input(powerButton): #Test for continued button press. If not pressed run brew script.
if(DEBUG):print("Run Brew script")
os.system('/home/pi/Ridiculous/brew.sh') # Execute the brew.sh bash script.
zeroMode() # Clear the accidental button presses.
elif GPIO.input(powerButton) == False: # If button press continues, wait 3 more seconds.
if(DEBUG):print("Waiting 2 more")
os.system('/home/pi/Ridiculous/vibrate.sh') # Effector movement to signal that the \
zeroMode()
time.sleep (2)
if GPIO.input(powerButton): #If button press does not continue, run the cable function.
if(DEBUG):print("Clearing zero position")
os.system('/home/pi/Ridiculous/clear_coordinates.sh') # Execute the brew.sh bash script.
#os.system('/home/pi/Ridiculous/all_tighten.sh')
zeroMode()
if GPIO.input(powerButton) == False: # If button press continues, wait 3 more seconds.
if(DEBUG):print("Waiting another 2 seconds.")
os.system('/home/pi/Ridiculous/vibrate.sh') # Effector movement to signal that the \
zeroMode()
time.sleep (2)
if GPIO.input(powerButton): #If button press does not continue, run the cable function.
if(DEBUG):print("Going into cable")
cable()
elif GPIO.input(powerButton) == False: #If button press still continues, run shutdown script.
if(DEBUG):print("Shutting Down")
os.system('/home/pi/Ridiculous/vibrate.sh') # Effector movement to signal that the \
time.sleep (2)
os.system('sudo shutdown -h now') # Execute the brew.sh bash script.
if GPIO.event_detected(northButton):
if(DEBUG):print("North button pressed")
os.system('/home/pi/Ridiculous/north.sh') #Moves effector "north" by a step number specified in "north.sh"
if GPIO.event_detected(westButton):
if(DEBUG):print("West button pressed")
os.system('/home/pi/Ridiculous/west.sh') #Moves effector "west" by a step number specified in "west.sh"
if GPIO.event_detected(eastButton):
if(DEBUG):print("East button pressed")
os.system('/home/pi/Ridiculous/east.sh') #Moves effector "east" by a step number specified in "east.sh"
if GPIO.event_detected(southButton):
if(DEBUG):print("South button pressed")
os.system('/home/pi/Ridiculous/south.sh') #Moves effector "south" by a step number specified in "south.sh"
def main():
while True:
boo()
try:
main()
except KeyboardInterrupt:
print ("ctrl+c pressed, exiting Event.py")
finally:
GPIO.cleanup()
#End