Hardware Reference
In-Depth Information
you can have a total of eight custom characters. To map the 20% character byte
array to custom character 0, type the following within your setup() function:
lcd.createChar(0, p20);
When you're ready to write a custom character to the display, place the cursor
in the right location and use the library's write() function with the ID number:
lcd.write((byte)0);
In the preceding line, (byte) casts, or changes, the 0 to a byte value. This is
necessary only when writing character ID 0 directly (without a variable that is
defined to 0), to prevent the Arduino compiler from throwing an error caused by
the variable type being ambiguous. Try removing the “byte cast” and observe
the error that the Arduino IDE displays. You can write other character IDs
without it, like this:
lcd.write(1);
Putting this all together, you can add the rest of the characters and put two
nested for() loops in your program loop to handle updating the progress bar.
The completed code looks like the code shown in Listing 10-2.
Listing 10-2: LCD Updating Progress Bar Code—LCD_progress_bar.ino
//LCD with Progress Bar
//Include the library code:
#include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
//Create the progress bar characters
byte p20[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
Search WWH ::




Custom Search