Extending the LiquidCrystal library

When using the LiquidCrystal library to output some text on an LCD on my Arduino Uno, I stumbled upon the following problem: if a text is displayed on the screen (let’s say “hello world!”) and you try to display another text (let’s say “bye”) you end up with the following text: “byelo world!”.

The reason for this is that the screen doesn’t clear a line before writing to it.

I could easily solve the problem in my code (just print spaces for all remaining characters) but I thought it would be more convenient if I built the capability directly into the Library. I added a function printLine(int line, const String text) which solves this task.

Download LiquidCrystalExt. To install you just have to unzip and copy it into the folder library either of the Arduino IDE or of your sketchbook.



const int LCD_WIDTH = 16;
const int LCD_HEIGHT = 2;

const int PIN_LCD_RS = 5;
const int PIN_LCD_ENABLE = 6;
const int PIN_LCD_D4 = 8;
const int PIN_LCD_D5 = 9;
const int PIN_LCD_D6 = 10;
const int PIN_LCD_D7 = 11;


// the setup routine runs once when you press reset:
void setup() {
  lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  lcd.printLine(0, "hello world!");
  lcd.printLine(0, "bye");

void loop() {
  while (true) {

Leave a comment

Your email address will not be published. Required fields are marked *