Start Your Journey with Linux Command Line
| 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 |
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.
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:
###
# #
###
# #
###
A seven-segment LED display shows digits and letters by lighting up a fixed set of seven bars, arranged as two vertical segments on each side plus one horizontal segment at the top, middle, and bottom. An optional eighth segment, the decimal point or DP, is used to display non-integer numbers. Because each digit is simply a combination of which segments are turned on, a display can represent all the values from 0 to 9, and with some creativity even letters and symbols.
In this lab the program does not control actual hardware. Instead, it draws the appearance of a seven-segment display in the console using the character #. Horizontal segments are drawn with three hashes, ###, while vertical segments use a single hash, #. Every digit is represented as five rows of text, so the letter 0, for example, is drawn as a top bar, two sides, and a bottom bar.
The solution maps each character to a tuple of five strings, one string per row of the display. A dictionary named dict1 holds the drawing rules for the digits 0 through 9 and even the decimal point. Because each entry is a tuple of five rows, drawing the full number is a matter of assembling those rows side by side for every digit.
The function seven_segment(number) loops over the five row positions. For each row index i, it builds a list of the current row for every digit in the number using a list comprehension, then joins those row pieces with two spaces and prints the resulting line. By printing five lines in total, the program reconstructs the entire multi-digit display row by row, exactly as a physical display would show it.
### and vertical segments as #.Because the display has three horizontal positions (top, middle, bottom) and two vertical spans, each digit is naturally drawn as five stacked lines, which the console renders as five rows of text.
The code looks up the digit in the dictionary to get its tuple of five rows, then for each row position it joins the matching row from every digit of the number and prints them together as one line.
The decimal point is an optional eighth segment used to show non-integer numbers. In the post it is drawn as a small hash at the bottom row of a placeholder column.
Yes. Because segments can be combined freely, you can add entries to the dictionary describing how letters and symbols should be drawn, and the same drawing function will display them.
Comments
Post a Comment
Your opinion matters, your voice makes us proud and happy. Your words are our motivation.