-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_display
46 lines (44 loc) · 1.53 KB
/
led_display
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
''' I tried this problem and solved it but could not get the numbers to print next to each other.
this solution in this file right now is not completely written by me. '''
digits = { '0': '1111110', # 0
'1': '0110000', # 1
'2': '1101101', # 2
'3': '1111001', # 3
'4': '0110011', # 4
'5': '1011011', # 5
'6': '1011111', # 6
'7': '1110000', # 7
'8': '1111111', # 8
'9': '1111011', # 9
}
def printNumber(num):
global digits
digs = str(num)
lines = [ '' for l in range(5) ]
for d in digs:
# only display segmets for a num with more than 0 digits
segs = [ [' ',' ',' '] for l in range(5) ]
# the 1's in the pattern of the digit are the segments to be turned on
ptrn = digits.get(d)
if ptrn[0] == '1':
segs[0][0] = segs[0][1] = segs[0][2] = '*'
if ptrn[1] == '1':
segs[0][2] = segs[1][2] = segs[2][2] = '*'
if ptrn[2] == '1':
segs[2][2] = segs[3][2] = segs[4][2] = '*'
if ptrn[3] == '1':
segs[4][0] = segs[4][1] = segs[4][2] = '*'
if ptrn[4] == '1':
segs[2][0] = segs[3][0] = segs[4][0] = '*'
if ptrn[5] == '1':
segs[0][0] = segs[1][0] = segs[2][0] = '*'
if ptrn[6] == '1':
segs[2][0] = segs[2][1] = segs[2][2] = '*'
for l in range(5):
#this line enables printing multiple digits next to each other
#by joining the characters in the segment array into a string
#The result is a horizonal line segment for multiple digit
lines[l] += ''.join(segs[l]) + ' '
for l in lines:
print(l)
printNumber(int(input("Enter the number you wish to display: ")))