-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_segment.py
More file actions
executable file
·49 lines (41 loc) · 1.1 KB
/
11_segment.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.1 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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
SDI = 11
RCLK = 12
SRCLK = 13
segCode = [0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80]
def print_msg():
print 'Program is running...'
print 'Please press Ctrl+C to end the program...'
def setup():
GPIO.setmode(GPIO.BOARD) #Number GPIOs by its physical location
GPIO.setup(SDI, GPIO.OUT)
GPIO.setup(RCLK, GPIO.OUT)
GPIO.setup(SRCLK, GPIO.OUT)
GPIO.output(SDI, GPIO.LOW)
GPIO.output(RCLK, GPIO.LOW)
GPIO.output(SRCLK, GPIO.LOW)
def hc595_shift(dat):
for bit in range(0, 8):
GPIO.output(SDI, 0x80 & (dat << bit))
GPIO.output(SRCLK, GPIO.HIGH)
time.sleep(0.001)
GPIO.output(SRCLK, GPIO.LOW)
GPIO.output(RCLK, GPIO.HIGH)
time.sleep(0.001)
GPIO.output(RCLK, GPIO.LOW)
def loop():
while True:
for i in range(0, len(segCode)):
hc595_shift(segCode[i])
time.sleep(0.5)
def destroy(): #When program ending, the function is executed.
GPIO.cleanup()
if __name__ == '__main__': #Program starting from here
print_msg()
setup()
try:
loop()
except KeyboardInterrupt:
destroy()