-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-gpio-pins.py
45 lines (38 loc) · 1.53 KB
/
test-gpio-pins.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
import RPi.GPIO as gpio
val = None;
pin = None;
state = None;
gpio.setmode(gpio.BCM)
# gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_DOWN)
# gpio.output(12, gpio.HIGH)
# gpio.output(12, gpio.LOW)
while(True):
try:
val = input("Enter GPIO number [0, 27] or set the current GPIO to [h | high] or [l | low]: ")
if (val.isdigit()):
# Print the ADC values.
print("\nCurrent GPIO: {}, state: {}\n".format(pin, state))
pin_no = int(val)
if (pin_no >= 0 and pin_no <= 27):
if (pin is not None):
print("@@@@ Switching GPIO {} -> {}".format(pin, pin_no))
pin = pin_no
gpio.setup(pin, gpio.OUT)
print("@@ GPIO {} is now set to OUT\n".format(pin))
else:
print("\n!!!! Value error; out of range. [0, 27]\n")
else:
if (pin is not None and (val == 'high' or val == 'h')):
state = 'high'
gpio.output(pin, gpio.HIGH)
print("\n@@ GPIO {} is now HIGH\n".format(pin))
elif (pin is not None and (val == 'low' or val == 'l')):
state = 'low'
gpio.output(pin, gpio.LOW)
print("\n@@ GPIO {} is now LOW\n".format(pin))
else:
print("\n!!!! Value error! Must enter either 'h' / 'high' for high or 'l' / 'low' for low.\n")
except KeyboardInterrupt:
print("@@ Keyboard Interrupt - exiting the test..")
gpio.cleanup()
exit();