-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelay_tester.py
50 lines (42 loc) · 1.54 KB
/
relay_tester.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
#!/usr/bin/python
#================================================================#
# Implemented by Michael Michael http://www.github.com/michmike
# Under MIT License
# https://raw.githubusercontent.com/michmike/Raspberry-PI-Q/master/LICENSE
#================================================================#
import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BCM)
# init list with pin numbers
pinList = [26]
# loop through pins and set mode and state to 'high'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# time to sleep in seconds between operations in the main loop
SleepTimeL = 20
# If a parameter is passed to end this script after a certain time, go ahead and execute on it
# Time is passed in seconds
if len(sys.argv) > 1:
startTime = time.time()
endTime = float(sys.argv[1])
print("Starting relay_tester.py to test the relay fan for %s seconds" % endTime)
try:
while 1 == 1:
for i in pinList:
print("turning on")
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTimeL);
print("turning off")
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTimeL);
if len(sys.argv) > 1:
elapsedTimeForNotification = time.time() - startTime
if elapsedTimeForNotification > endTime:
break
except KeyboardInterrupt:
print("Exiting after a keyboard cancellation...Goodbye...")
finally:
GPIO.cleanup()
print("Finished cleanup of GPIO")