-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlighttree.pl
More file actions
executable file
·121 lines (108 loc) · 3.4 KB
/
Copy pathlighttree.pl
File metadata and controls
executable file
·121 lines (108 loc) · 3.4 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
116
117
118
119
120
121
#!/usr/bin/python
import RPi.GPIO as GPIO
import sys
import time
import os
GPIO.setmode(GPIO.BCM)
# Relays 1 through 8, in order. These are active-LOW pins, i.e., sending a LOW
# output turns on the corresponding relay, and sending a HIGH turns off the
# relay.
pins = [18, 25, 10, 24, 23, 22, 27, 17]
# These are the two hardware pushbutton inputs; the input will show 0 if the
# button is pressed, 1 if it's not.
#
# "READY" button on post
btnREADY = 8
# Actual start button
btnSTART = 7
#RuntimeWarning: This channel is already in use, continuing anyway.
#Use GPIO.setwarnings(False) to disable warnings.
GPIO.setwarnings(False)
def showInitializationSequence():
for p in range(0, 5):
for rep in range(1,4):
GPIO.output(pins[p], GPIO.LOW)
time.sleep(0.0625)
GPIO.output(pins[p], GPIO.HIGH)
time.sleep(0.0625)
GPIO.output(pins[p], GPIO.LOW)
time.sleep(1)
for pp in pins:
GPIO.output(pp, GPIO.HIGH)
def showReadySequence():
for p in range(1,6):
GPIO.output(pins[5 - p], GPIO.LOW)
time.sleep(0.125)
for p in range(1,6):
GPIO.output(pins[5 - p], GPIO.HIGH)
time.sleep(0.125)
for rep in range(1,4):
GPIO.output(pins[0], GPIO.LOW)
time.sleep(0.0625)
GPIO.output(pins[0], GPIO.HIGH)
time.sleep(0.0625)
def showStartSequence():
# "Standard" drag racing tree is 0.5 sec between lights, but that's
# kinda slow for a PWD audience to wait each time.
pace = 0.25 # Time between lights, in seconds.
for p in range(1,5):
GPIO.output(pins[p - 1], GPIO.LOW)
time.sleep(pace)
GPIO.output(pins[p - 1], GPIO.HIGH)
GPIO.output(pins[4], GPIO.LOW)
time.sleep(pace)
GPIO.output(pins[7], GPIO.LOW)
time.sleep(1)
GPIO.output(pins[4], GPIO.HIGH)
GPIO.output(pins[7], GPIO.HIGH)
def showShutdownSequence():
for pp in pins:
GPIO.output(pp, GPIO.LOW)
for p in range(0, 5):
time.sleep(0.5)
GPIO.output(pins[p], GPIO.HIGH)
# Asynchronously invoked when the START button changes state.
def onSTART(pin):
if GPIO.input(pin) == 0:
# Button pressed
showStartSequence()
ready_press = 0
# Asynchronously invoked when the READY button on the pole changes state.
def onREADY(pin):
global ready_press
if GPIO.input(pin) == 1:
# Button released, cancel timing how long it was held
ready_press = 0
elif ready_press == 0:
ready_press = time.time()
showReadySequence()
# else ignore apparent button "press" while already held
# Set up all the pins we're using
def startup():
# Turn off all the relays
for p in pins:
GPIO.setup(p, GPIO.OUT, initial=GPIO.HIGH)
# Set up pushbutton handling
GPIO.setup(btnREADY, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(btnREADY, GPIO.BOTH, bouncetime=100,
callback=onREADY)
GPIO.setup(btnSTART, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(btnSTART, GPIO.BOTH, bouncetime=200,
callback=onSTART)
# Show that we're open for business
showInitializationSequence()
startup()
try:
# Any button presses will invoke the event handlers in another thread. The
# program will terminate if we just exit the main thread, so instead we have
# to wait forever in this loop.
while (1):
time.sleep(1)
if ready_press != 0:
howlong = time.time() - ready_press
if howlong > 5.0:
showShutdownSequence()
os.system("shutdown -h now")
ready_press = 0
finally:
GPIO.cleanup()