-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompTimer2.py
More file actions
executable file
·64 lines (50 loc) · 1.25 KB
/
Copy pathcompTimer2.py
File metadata and controls
executable file
·64 lines (50 loc) · 1.25 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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import os.path
import sys
GPIO.setmode(GPIO.BCM)
a_pin = 18
b_pin = 23
GPIO.setup(a_pin, GPIO.IN)
GPIO.setup(b_pin, GPIO.IN)
#start = time.time()
#stop = time.time()
gateState = False
gateTwoState = False
if (GPIO.input(a_pin) == False):
print "first sensor ready"
else:
print "check first sensor alignment"
sys.exit(0)
if (GPIO.input(b_pin) == False):
print "second sensor ready"
else:
print "check second sensor alignment"
sys.exit(0)
outfile = os.path.expanduser("~/LaserTimer/carTimes.txt")
try:
for i in range(10):
run = raw_input("Team and run number: ")
print "ready for " + run
firstIn = False
firstOut = False
while True:
if (GPIO.input(a_pin) == True ):
if (firstIn == False):
start = time.time()
print "first gate triggered"
firstIn = True
if (GPIO.input(b_pin) == True ):
if (firstIn == True and firstOut == False):
stop = time.time()
print "second gate ..."
firstOut = True
t = stop - start
print "... Time: ", t , "s"
with open(outfile, "a") as f:
f.writelines("\n" + time.asctime() + "\n" + run + ": " + str(t))
break
GPIO.cleanup()
except KeyboardInterrupt:
GPIO.cleanup()