-
Notifications
You must be signed in to change notification settings - Fork 1
/
inside_gate.py
65 lines (52 loc) · 1.5 KB
/
inside_gate.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
#inside_Gate
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers
GPIO.setwarnings(False)
RELAIS_1_GPIO = 17
RELAIS_2_GPIO = 27
RELAIS_3_GPIO = 5
RELAIS_4_GPIO = 6
pirPin = 22
GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Assign mode
GPIO.setup(RELAIS_2_GPIO, GPIO.OUT)
GPIO.setup(RELAIS_3_GPIO, GPIO.OUT)
GPIO.setup(RELAIS_4_GPIO, GPIO.OUT)
GPIO.setup(pirPin, GPIO.IN)
def extendActuator():
print("Extneding")
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_2_GPIO, GPIO.LOW)
GPIO.output(RELAIS_3_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_4_GPIO, GPIO.LOW)
def retractActuator():
print("Retracting")
GPIO.output(RELAIS_1_GPIO, GPIO.LOW)
GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_3_GPIO, GPIO.LOW)
GPIO.output(RELAIS_4_GPIO, GPIO.HIGH)
def stopActuator():
print("Stop")
GPIO.output(RELAIS_1_GPIO, GPIO.LOW)
GPIO.output(RELAIS_2_GPIO, GPIO.LOW)
GPIO.output(RELAIS_3_GPIO, GPIO.LOW)
GPIO.output(RELAIS_4_GPIO, GPIO.LOW)
def operation(pirPin):
retractActuator()
time.sleep(10)
stopActuator()
time.sleep(1)
extendActuator()
time.sleep(10)
stopActuator()
time.sleep(1)
print("Gate Control (CTRL+C to exit)")
time.sleep(.2)
print("Ready")
try:
GPIO.add_event_detect(pirPin, GPIO.RISING, callback=operation)
while 1:
time.sleep(1)
except KeyboardInterrupt:
print("Quit")
GPIO.cleanup()