7 Segment LED control.
Controls that simulate instrumentation hardware are very
popular in applications such as process-control, medical monitoring circuit
simulation and many others. One of the most popular types of display is the old
seven segment LED used for many years on video-recorders, watches and just about
every other electronic gizmo that requires a numeric display. The look of the
seven segment LED had sunk into the consciousness of mankind so much that even
when hi-resolution displays with infinitely scalable fonts are available, the
good old red or green LED display is still the chosen method of clearly
displaying numbers.
This article will show you how such a control can be created and later you'll
see how to put a collection of them together to create numeric instrumentation
displays.
Defining the look.
The classic seven segment LED display is actually eight
lights arranged in a pattern. Seven of the lights are arranged in a figure "8"
and can be lit to represent any number 0-9 and for some applications there are
even representations of the letters A-F so that hexadecimal values may be shown.
The eighth light is the decimal point which can be used to enable the
representation of floating point numbers. Some LED displays actually have a
colon in addition to the decimal point to enable the display of time in 15:34
format or perhaps latitude in 43:27:12 format. This LED display will follow is
even more useful and is laid out as shown in figure 1. The extra segments can be
used as a colon or to create a + sign in combination with the "G" segment.

Figure 1. The layout of the LED control
The segments are drawn by creating and filling a GraphicsPath
for each one. These can be filled in two ways, with the illuminated LED colour
or with another colour to simulate the appearance of an inactive segment.
The code that draws the individual segments is shown
here. To enable the control to be scaled the lines are always drawn using
floating point values that can be stretched easily. The LED is assumed to occupy
a 10*10 character which is divided up using floating point values. The width and
height of the control is divided by 10 and used to form a transformation matrix
that scales the imaginary characters to the size of the control.
The pattern of lit segments that represent the numbers is
determined by a character. This enables the control to display a few other
symbols that might be useful. The character set for the LEDControl is shown in
Figure 2

Figure 2. The LEDControl character set.
The character set encompasses the numerals 0-9, the
hexadecimal numbers A-F, the + and - signs and the "r" so that the word Error
can be spelled out. Each character can have a decimal point also.
The characters are drawn by a combination of segments. If the
dark segments are supposed to be a neutral colour different from the background
then they also need filling and provision is made for that choice.
The code that creates all the characters is shown here.
This control can be used directly at runtime or added to a
user control to create composite components. The next article describes how to
create an LED digital clock with the LED control.
Read the LED Clock article.
You can find the Source Code files here.
Return to the main menu.