/
launcher.py.bak
executable file
·179 lines (153 loc) · 4.47 KB
/
launcher.py.bak
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
#!/usr/bin/env python
# T-Shirt Launcher for Minnesota Roller Girls
# Using a Raspberry Pi, Darlington Transistor Array, Analog inputs for PSI (code in progress),
# and two buttoms for selecting the barrel and firing.
# David M. N. Bryan
# Attribution-NonCommercial-ShareAlike 4.0 International
import RPi.GPIO as GPIO, time
# Define our relay outputs
TSHIRT1=4
TSHIRT2=17
TSHIRT3=18
TSHIRT4=22
# Define our LED outputs
LED1=2
LED2=3
LED3=14
LED4=15
LED5=24
# Define our input buttons here
BUTTON1=27
BUTTON2=23
# Setup our GPIO lines
GPIO.setmode(GPIO.BCM)
# Output to the Darlington Driver for the 12V sprinkler valves
GPIO.setup(TSHIRT1, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(TSHIRT2, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(TSHIRT3, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(TSHIRT4, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
#Setup the LED lights for outputs
GPIO.setup(LED1, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED2, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED3, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED4, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED5, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN)
# Setup the Inputs
GPIO.setup(BUTTON1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Setup a t-shirt shooting function
valve_sleep_time=.08
def fireshirt(TNUMBER):
global F_TIME
global valve_sleep_time
if (TNUMBER==1):
TSHIRTN=TSHIRT1
elif (TNUMBER==2):
TSHIRTN=TSHIRT2
valve_sleep_time=.18
elif (TNUMBER==3):
TSHIRTN=TSHIRT3
elif (TNUMBER==4):
TSHIRTN=TSHIRT4
else:
TSHIRTN=0
if(ready==1):
print "Turning on valve for", valve_sleep_time, "second using pin: ", TSHIRTN
blink_led(TNUMBER, 3, .1)
GPIO.output(TSHIRTN, True)
time.sleep(valve_sleep_time)
GPIO.output(TSHIRTN, False)
F_TIME=time.time()
blink_led(TNUMBER, 6, .5)
else:
#print "Fire command requested for", THSIRTN, " but we're not ready..."
print('Fire button detected, but time out not yet passed: Firetime: {0} Pushtime: {1}'.format(F_TIME,time.time()))
def light_led(LED_NUM):
if(LED_NUM==1):
print('Turning on LED PIN: %s'%LED1)
GPIO.output(LED1, True)
GPIO.output(LED2, False)
GPIO.output(LED3, False)
GPIO.output(LED4, False)
if(LED_NUM==2):
print('Turning on LED PIN: %s'%LED2)
GPIO.output(LED1, False)
GPIO.output(LED2, True)
GPIO.output(LED3, False)
GPIO.output(LED4, False)
if(LED_NUM==3):
print('Turning on LED PIN: %s'%LED3)
GPIO.output(LED1, False)
GPIO.output(LED2, False)
GPIO.output(LED3, True)
GPIO.output(LED4, False)
if(LED_NUM==4):
print('Turning on LED PIN: %s'%LED4)
GPIO.output(LED1, False)
GPIO.output(LED2, False)
GPIO.output(LED3, False)
GPIO.output(LED4, True)
if(LED_NUM==5):
print('Turning on LED PIN: %s'%LED5)
GPIO.output(LED5, False)
def blink_led(LED_NUM, REPS, DELAY):
if(LED_NUM==1):
LEDN=LED1
if(LED_NUM==2):
LEDN=LED2
if(LED_NUM==3):
LEDN=LED3
if(LED_NUM==4):
LEDN=LED4
if(LED_NUM==5):
LEDN=LED5
for x in range(0, REPS):
GPIO.output(LEDN, True)
time.sleep(DELAY)
GPIO.output(LEDN, False)
time.sleep(DELAY)
GPIO.output(LEDN, True)
LMODE=1
light_led(LMODE)
MAX_MODES=4
# These answer button pushes.
def my_callback_sel(BUTTON1):
global LMODE
# We have a momentary switch that we want to increment each time it's pressed, and light up LED X.
if(LMODE<=0):
LMODE=0
elif(LMODE==MAX_MODES):
LMODE=0
LMODE += 1
print('Setting launch mode to %s'%LMODE)
light_led(LMODE)
BUTTON2_P=0
def my_callback_fire(BUTTON2):
global BUTTON2_P
BUTTON2_P += 1
if(BUTTON2_P<=1):
F_TIME2 = F_TIME + 4
ptime=time.time()
if(F_TIME2<=ptime):
ready=1
print('Fireing using launch mode %s'%LMODE)
BUTTON_P=0
fireshirt(LMODE)
else:
print('Waiting for delay_time to timeout... F_TIME: {0} Current: {1}' .format(F_TIME,ptime))
ready=0
else:
print('Second push detected...')
BUTTON2_P=0
GPIO.add_event_detect(BUTTON1, GPIO.FALLING, callback=my_callback_sel, bouncetime=300)
GPIO.add_event_detect(BUTTON2, GPIO.FALLING, callback=my_callback_fire, bouncetime=300)
#GPIO.add_interrupt_callback(BUTTON1, my_callback_sel, edge='falling', threaded_callback=False, debounce_timeout_ms=300)
#GPIO.add_interrupt_callback(BUTTON2, my_callback_fire, edge='falling', threaded_callback=False, debounce_timeout_ms=300)
F_TIME=time.time()
ready=1
while True:
global ready
time.sleep(.1)
if(ready==0):
# Blink the status LED.
blink_led(5, 5, .5)