Menu
CoddyTech

Place Text with setCursor

Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 7 of 24.

The LCD keeps a cursor: the place where the next letter goes. Each letter moves it one column to the right. After lcd.begin() it sits at the top left.

lcd.setCursor(column, row) moves it. Both count from 0: columns 0 to 15, rows 0 and 1. The column comes first.

lcd.setCursor(0, 0);   // top left
lcd.print("Top");
lcd.setCursor(4, 1);   // bottom row, fifth column
lcd.print("Bottom");

To end a word at the right edge, start it at 16 minus its length. A 5-letter word starts at column 11 and fills columns 11 to 15.

challenge icon

Challenge

Easy

Put a word in two corners:

  • Hello at the start of the top row
  • World at the end of the bottom row, its last letter in the last column

Press Run, then Check.

Try it yourself

#include <LiquidCrystal.h>

// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);

  // Hello at the start of the top row
  // World at the end of the bottom row
}

void loop() {
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Displays and Sensors

Practice on your own: Arduino playground