Hardware Reference
In-Depth Information
because you want to the text to be printed to position (0,0) , which is already
the default starting location. In the loop, the cursor is always set back to posi-
tion (0,1) so that the number you print every second overwrites the previous
number. The display updates once per second with the incremented time value.
CreatingSpecialCharactersandAnimations
What if you want to display information that cannot be expressed using normal
text? Maybe you want to add a Greek letter, a degree sign, or some progress
bars. Thankfully, the LiquidCrystal library supports the definition of custom
characters that can be written to the display. In the next example, you use this
capability to make an animated progress bar that scrolls across the display.
After that, you take advantage of custom characters to add a degree sign when
measuring and displaying temperature.
Creating a custom character is pretty straightforward. If you take a close look
at your LCD, you'll see that each character block is actually made up of a 5n8
grid of pixels. To create a custom character, you simply have to define the value
of each of these pixels and send that information to the display. To try this out,
you make a series of characters that will fill the second row of the display with
an animated progress bar. Because each character space is 5 pixels wide, there
will be a total of five custom characters: one with one column filled, one with
two columns filled, and so on.
At the top of your sketch where you want to use the custom characters, cre-
ate a byte array with 1s representing pixels that will be turned on and with 0s
representing pixels that will be turned off. The byte array representing the char-
acter that fills the first column (or the first 20% of the character) looks like this:
byte p20[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
I chose to call this byte array p20 , to represent that it is filling 20 percent of
one character block (the p stands for percent).
In the setup() function, call the createChar() function to assign your byte
array to a custom character ID. Custom character IDs start at 0 and go up to 7, so
Search WWH ::




Custom Search