-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseven_segment.py
51 lines (40 loc) · 950 Bytes
/
seven_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
import RPi.GPIO as GPIO
import time
segment_pins = [20, 21, 26, 19, 13, 12, 16]
segment_names = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
GPIO.setmode(GPIO.BCM)
digits = [
'abcdef', #0
'bc', #1
'abdeg', #2
'abcdg', #3
'bcfg', #4
'acdfg', #5
'acdefg', #6
'abc', #7
'abcdefg', #8
'abcfg', #9
]
def clear_all_segments():
for x in segment_pins:
GPIO.output(x, GPIO.LOW)
def set_digit(x):
clear_all_segments()
segments_to_light = digits[x]
i = 0
while i < len(segment_names):
if segments_to_light.find(segment_names[i]) != -1:
GPIO.output(segment_pins[i], GPIO.HIGH)
i = i + 1
for x in segment_pins:
GPIO.setup(x, GPIO.OUT)
GPIO.output(x, GPIO.LOW)
for x in segment_pins:
GPIO.output(x, GPIO.HIGH)
time.sleep(.1)
j = 0
while j < 10:
set_digit(j)
time.sleep(1)
j = j+1
GPIO.cleanup()