-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathled-control.py
executable file
·75 lines (61 loc) · 1.76 KB
/
led-control.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
66
67
68
69
70
71
72
73
74
# LED-Control
# Jeremy C. Radwan
# May 18, 2019
#
# This Python script is a consolidation of LEDs-Off and LEDs-On.
#
# Modification History:
#
import RPi.GPIO as GPIO
import sys
CMD_HELP = "\nLED-Control syntax: python led-control.py on|off [-v (for verbose messages)]\n"
debug = False
# ledrows (xled0-5) associated gpio pins
# NOTE: these numbers correspond not to the PHYSICAL pin numbers, but the gX numbers listed on the schematic)
# example: xled5 = g25 = pin 22
ledrows = [20, 21, 22, 23, 24, 25]
# ledcols (col0-11) associated gpio pins
# NOTE: these numbers correspond not to the PHYSICAL pin numbers, but the gX numbers listed on the schematic)
# example col0 = g26 = pin 37
ledcols = [26, 27, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# check command-line arguments
if len(sys.argv) <> 1:
if str.lower(sys.argv[1]) == "on":
action = "on"
gpio_row = GPIO.HIGH
gpio_col = GPIO.LOW
elif str.lower(sys.argv[1]) == "off":
action = "off"
gpio_row = GPIO.LOW
gpio_col = GPIO.HIGH
else:
sys.exit(CMD_HELP)
if len(sys.argv) == 3:
if str.lower(sys.argv[2]) == "-v":
debug = True
else:
sys.exit(CMD_HELP)
else:
sys.exit(CMD_HELP)
if debug:
print "\nTurning", action, "all PiDP-11 LEDs ...\n"
# act on ledrows
rowcount = 0
for row in ledrows:
if debug:
print "Turning", action, "xled" + str(rowcount) + " (pin " + str(row) + ")"
rowcount = rowcount + 1
GPIO.setup(row, GPIO.OUT, initial = gpio_row)
if debug:
print ""
# act on ledcols
colcount = 0
for col in ledcols:
if debug:
print "Turning", action, "col" + str(colcount) + " (pin " + str(col) + ")"
colcount = colcount + 1
GPIO.setup(col, GPIO.OUT, initial = gpio_col)
if debug:
print "\nDone!\n"