-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-clock.py
More file actions
executable file
·62 lines (56 loc) · 2.03 KB
/
Copy pathtest-clock.py
File metadata and controls
executable file
·62 lines (56 loc) · 2.03 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
#!/usr/bin/env python
#External settings
import settings
#External modules
import time
if(settings.slaveBipolar):
print("Use this to test clock impulses on alternating pins "+str(settings.slavePinEven)+" and "+str(settings.slavePinOdd)+" (per settings.py)")
else:
print("Use this to test clock impulses on pin "+str(settings.slavePin)+" (per settings.py)")
if settings.piMode:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
if settings.slaveBipolar:
GPIO.setup(settings.slavePinOdd, GPIO.OUT)
GPIO.setup(settings.slavePinEven, GPIO.OUT)
else:
GPIO.setup(settings.slavePin, GPIO.OUT)
#end pi mode
else:
print('Please enable piMode in settings.py, if this is indeed running on a Pi.')
exit()
try:
print("Type Ctrl+C to exit.");
impDurLast = 0.2
impCount = 0
while 1:
try:
impDur = input("Duration of impulse in seconds (Enter for "+str(impDurLast)+"): ")
except SyntaxError: #empty string
impDur = impDurLast
if impDur > 1:
impDur = 1
if impDur < 0.01:
impDur = 0.01
impDurLast = impDur
impCount = impCount+1
impPin = False
if settings.slaveBipolar:
impPin = settings.slavePinOdd if impCount % 2 else settings.slavePinEven
else:
impPin = settings.slavePin
print("Impulse "+str(impCount)+": Waiting then impulsing pin "+str(impPin)+" for "+str(impDur)+" seconds")
time.sleep(impDur) #so it will crash before setting the pin high, if it's going to crash
GPIO.output(impPin, GPIO.HIGH)
time.sleep(impDur)
GPIO.output(impPin, GPIO.LOW)
except AttributeError: #Easier to ask forgiveness than permission (EAFP) - http://stackoverflow.com/a/610923
print("\r\nAttributeError. Please ensure your settings.py includes all items from settings-sample.py.")
except KeyboardInterrupt:
print("\r\nBye!")
# except:
# print("Error")
finally:
if settings.piMode:
GPIO.cleanup()
#end try/except/finally