Given a 16x2 LCD, what will be the cursor position after running this code?
lcd.setCursor(5, 1);
Assume the cursor starts at (0,0).
lcd.setCursor(5, 1);
The first number is the column (x), the second is the row (y).
The setCursor function takes two arguments: column and row. So setCursor(5, 1) moves the cursor to column 5, row 1.
What will be displayed on the LCD after this code runs?
lcd.setCursor(0, 0);
lcd.print("Hi");
lcd.setCursor(3, 0);
lcd.print("There");lcd.setCursor(0, 0); lcd.print("Hi"); lcd.setCursor(3, 0); lcd.print("There");
Think about spaces between printed words and cursor positions.
The first print writes "Hi" starting at column 0. Then the cursor moves to column 3 and prints "There". So the LCD shows "Hi There" with a space at column 2.
What error will this code cause and why?
lcd.setCursor(16, 0);
lcd.print("Hello");lcd.setCursor(16, 0); lcd.print("Hello");
Remember the LCD columns are 0 to 15 for a 16-column display.
Column 16 is outside the valid range (0-15) for a 16-column LCD. This causes a runtime error or undefined behavior depending on the library.
Choose the correct code to set the cursor to column 4, row 1 on a 16x2 LCD.
Remember columns and rows start counting at 0.
Columns and rows start at 0, so column 4 is the fifth column, and row 1 is the second row.
A 20x4 LCD has 20 columns and 4 rows. How many characters fit on the screen? And what is the correct cursor position to print at the last character on the last row?
Count columns * rows for total characters. Remember zero-based indexing for cursor.
20 columns * 4 rows = 80 characters total. The last column is 19 (0-based), last row is 3 (0-based), so cursor at (19, 3) is last character.
