-->

Python 2.4.1.6 LAB: A LED Display

Python Code to make a Seven Led Display

Seven LED Display

Exactly, what you see in the picture on top is a sample of a seven led display which uses a decimal number from 0-9 for as many digits as needed. Also, alpha characters (letters and symbols)can be used.

Figure.1

Why is it called "Seven Segment"?

Simply because it contains seven elements as shown in Figure.1. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom. The optional decimal point (an "eighth segment", referred to as DP) is used for the display of non-integer numbers.

Figure.2

As shown in Figure.2, this is how the numbers are shown. For example, "0" means all segments from A-G are led(shown), "1" means B and C are shown.

And below table shows us the plan of our code

Seven Segments-LED display

If you want to get a full idea about How Seven Segment LED Display works, you will find a slideshow in the end of the post.

Solution Code

We will code/draw each segment as "#". Note, the "horizontal segments" have ###, "vertical segments" have #. So, "0" will look like below:

###
#  #
#  #
#  #
###

While "8" will show like this in the console:

###
#  #
###
#  #
###

dict1 = {
    '0': ('###', '# #', '# #', '# #', '###'),
    '1': ('  #', '  #', '  #', '  #', '  #'),
    '2': ('###', '  #', '###', '#  ', '###'),
    '3': ('###', '  #', '###', '  #', '###'),
    '4': ('# #', '# #', '###', '  #', '  #'),
    '5': ('###', '#  ', '###', '  #', '###'),
    '6': ('###', '#  ', '###', '# #', '###'),
    '7': ('###', '  #', '  #', '  #', '  #'),
    '8': ('###', '# #', '###', '# #', '###'),
    '9': ('###', '# #', '###', '  #', '###'),
    '.': ('   ', '   ', '   ', '   ', '  #'),
}
number = input("Please Enter a Positive Number: ")  
def seven_segment(number):
    for i in range(5):
        digits = [dict1[digit] for digit in str(number)]
        print("  ".join(segment[i] for segment in digits))
seven_segment(number)

And here's the Seven-Segment LED system information for further readings:

Post a Comment

0 Comments