Draw Custom Characters
Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 10 of 24.
Each character on the LCD is a grid of 5 by 8 dots. You can design up to eight of your own, numbered 0 to 7. Describe one with 8 rows, each a 5-bit pattern where 1 is a lit dot:
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000
};lcd.createChar(0, heart) stores it as character 0. lcd.write(byte(0)) draws it where the cursor is. print(0) would draw the digit 0 instead.
One trap: to store a character, the library points the screen at its character memory, and it stays pointed there. Anything printed next goes into that memory, not onto the screen. So call lcd.setCursor() (or lcd.clear()) after createChar(), before you print.
lcd.createChar(0, heart);
lcd.setCursor(0, 0); // back to the screen
lcd.write(byte(0));Challenge
MediumThe starter has a smiley design. Say hi with it:
- store it as character 0 with
lcd.createChar() - move the cursor to the top left
- print
Hi(with a space), then draw the smiley
Press Run, then Check.
Try it yourself
#include <LiquidCrystal.h>
// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte smiley[8] = {
0b00000,
0b01010,
0b01010,
0b00000,
0b10001,
0b01110,
0b00000,
0b00000
};
void setup() {
lcd.begin(16, 2);
// store the smiley as character 0, then print "Hi " and the smiley
}
void loop() {
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Displays and Sensors
1Seven-Segment Displays
Seven-Segment DisplayDigit Patterns in BytesCount on the DisplayCountdown to ZeroDice Roller2Character LCD
Hello on the LCDPlace Text with setCursorLive Numbers on the LCDClear Leftover DigitsDraw Custom CharactersScrolling TextPractice on your own: Arduino playground