-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestOneGate.py
More file actions
42 lines (31 loc) · 810 Bytes
/
Copy pathtestOneGate.py
File metadata and controls
42 lines (31 loc) · 810 Bytes
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
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# this is the input pin. For the
# Vernier gate, this is pin 0 (DIO0)
a_pin = 18
GPIO.setup(a_pin, GPIO.IN)
# define initial settings
start = time.time()
stop = time.time()
firstcross = False
secondCross = False
crosses = 0
# initial gate state with light
gateState = True
try:
while True:
if (GPIO.input(a_pin) != gateState):
gateState = not gateState
if (gateState == True):
crosses = crosses + 1
if (gateState == True and crosses%2 == 1):
start = time.time()
print "first gate triggered"
if (gateState == True and crosses%2 == 0):
stop = time.time()
print "second gate ..."
if stop - start > 0.1:
print "... Time: ", stop - start, "s"
except KeyboardInterrupt:
GPIO.cleanup()