2

This example sketch shows how to use the setCursor() method to reposition the cursor. To move the cursor, just call setCursor() with a row and column position. For example, for a 2x16 display:

lcd.setCursor(0, 0); // top left
lcd.setCursor(15, 0); // top right
lcd.setCursor(0, 1); // bottom left
lcd.setCursor(15, 1); // bottom right

I am not able to understand the above code.Can anyone please give the clarification for the same?

Patrick Trentin
  • 7,126
  • 3
  • 23
  • 40
Reshu Singh
  • 65
  • 1
  • 2
  • 5

1 Answers1

6

The line lcd.setCursor() moves the cursor. The cursor is the position of the lertter you want the text to begin displaying at. lcd.setCursor() takes two values: an x position and a y position. It takes them in this order: lcd.setCursor(x, y).

A 2x16 display means that it has 2 rows and 16 columns of characters, or 2 y values and 16 x values.

In Arduino code and in most c-type languages you start counting at 0, this means that to get the first column you need to tell the Arduino to look at x of 0. Or to put a letter in the last column on the first row you would need to tell the Arduino to move the cursor to: (15, 0).

Example Display

The display will look like this:

enter image description here

Community
  • 1
  • 1
Morgoth
  • 4,935
  • 8
  • 40
  • 66