-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09_segment.py
executable file
·66 lines (58 loc) · 1.4 KB
/
09_segment.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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
#pins = [11,12,13,15,16,18,22,7]
pins = [7,22,18,16,15,13,12,11]
dats = {"0":0x3f,
"1":0x06,
"2":0x5b,
"3":0x4f,
"4":0x66,
"5":0x6d,
"6":0x7d,
"7":0x07,
"8":0x7f,
"9":0x6f,
"A":0x77,
"b":0x7c,
"C":0x39,
"d":0x5e,
"E":0x79,
"F":0x71,
".":0x80}
for key in dats:
print key, "corresponds to", bin(dats[key])
def setup():
GPIO.setmode(GPIO.BOARD)
for pin in pins:
GPIO.setup(pin, GPIO.OUT) # Set pin mode as output
GPIO.output(pin, GPIO.LOW)
def writeOneByte(val, pins):
bin_val =str(bin(val))[2:].zfill(8)
print (bin_val)
for pin in range(0,8):
print (pin, int(bin_val[pin]))
GPIO.output (pins[pin], int(bin_val[pin]))
# GPIO.output(11, val & (0x01 << 0))
# GPIO.output(12, val & (0x01 << 1))
# GPIO.output(13, val & (0x01 << 2))
# GPIO.output(15, val & (0x01 << 3))
# GPIO.output(16, val & (0x01 << 4))
# GPIO.output(18, val & (0x01 << 5))
# GPIO.output(22, val & (0x01 << 6))
# GPIO.output(7, val & (0x01 << 7))
def loop():
while True:
for val in dats:
writeOneByte(dats[val], pins=pins)
time.sleep(0.5)
def destroy():
for pin in pins:
GPIO.output(pin, GPIO.LOW)
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()