[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
Here's a program to simulate those scrolling LED signs commonly seen at Burger King and other favorite watering holes.
Background & Techniques
The idea for this program actually popped into my head last week while browsing the July issue of Nut and Volts - a gadgeteers electronic magazine. One article there is "Build this Scrolling LED Clock". " Well, we can do that without any extra hardware" thinks I. And we could.
First, how to get the fonts? I spent an hour or so searching for existing fonts without much luck. Defining the shapes for numerals 0-9 by hand wouldn't be too bad, but I decided I wanted to the full "Burgerking" experience. I spent a day programming down a dead end path using the Tcanvas Textout procedure to write text onto a bitmap and then digitizing LED sized chunks - if more than half of the pixels are black, call the LED on, otherwise off. The result was very, very ugly. Character lines and curves just don't line up with LED boundaries well enough to make this approach feasible. So back to the drawing board.
Actually back to the web - this time I found two downloadable programs LEDSign - a Java app that displays scrolling LED signage, and LEDFont - a program to convert TrueType fonts to LED font files in a format usable by LEDSign. The font files generated by LEDFont and used by LEDSign are plain text and straightforward so I decided to use their format. (For some reason, probably historical, they don't allow for defining a space character, so I ended up generating that character in the program at font load time. )
The program itself is not too complex - about 300 lines of user code - we'll call it Intermediate. I included controls to let the user set the message text and font, and LED size and colors. A TLEDChar record type defines a single character - it contains the Charwidth integer variable and a doubly dimensioned dynamic array of bytes (rows and columns of the LED image and with 0 = off and 1= on). A Chars array contains TLEDChar records for all 256 possible characters. Undefined characters can be identified by a 0 CharWidth value. The LoadFont procedure loads the Chars array from a font file selected by the user.
Characters are generated in a temporary bitmap and then copied to a TImage for display. The DrawLED function generates a specified character in the bitmap starting at a specified location.
Once the LED message is built, Copyrect is used to copy it to the visible TImage. Now we need to scroll it. A loop is used to copy the rightmost part of the bitmap (from starting position that increases by 1 LED each time through) to the leftmost part of the image. Then the un-copied leftmost part of the bitmap is copied to the rightmost part of the image. This gives the illusion that the message is scrolling left. A user controllable speedbar sets the milliseconds to delay between images.
Addendum Feb. 21, 2003: A new version posted today incorporates a couple of changes made as a result of users' requests. A new tabsheet now allows date/times in various formats to be displayed. And messages may now optionally be displayed in a separate resizable window. From the programmer's point of view, the tricky part was finding how to display tabsheet tabs "grayed out" when the control is disabled. It does not happen automatically as with most controls. An OnDrawTab exit from the TPageControl did handle it though.
Addendum April 16, 2004: An instructor teaching English in China is using Scrolling LEDs to present new vocabulary and prompted today's update. He asked that program settings be preserved from run to run, which seemed like a good idea to me. So now font and screen information is saved for each run restored when the program is next started (In a text file named LEDS.ini).
Addendum September 7, 2004: The same fellow who prompted the April 16 changes wondered if it would be feasible to add a "countdown" timer so he he keep track of the time remaining before his tour of duty is up. Today's change implements that feature. Symbols &dt and &ct can be inserted in message text to include current date and countdown time respectively. Separate tab pages define the format for date and countdown time time fields. .
Running/Exploring the Program
Note: The single font I generated using the LEDFont program is named arial.led and is the default font. Fonts copied from the LEDSign download have a .font suffix and several are also included.
Suggestions for Further Explorations
Copyright © 2000-2017, Gary Darby All rights reserved.