Liquid Crystal Display (LiquidCrystal Class)

This library allows for the control of Liquid Crystal Displays (LCDs) based on the Hitachi HD44780 (or a compatible) chip set, which is found on most text-based LCDs. The library works with either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and optionally, the rw control lines).

To use this library, describe #include <liquidcrystal.h> and generate an instance like LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2).

Constructor for LiquidCrystal

Description

Generates an object of LiquidCrystal.

Syntax

LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)

Parameters

rs: The number of the Arduino pin that is connected to the RS pin on the LCD
rw: The number of the Arduino pin that is connected to the RW pin on the LCD (optional)
enable: The number of the Arduino pin that is connected to the enable pin on the LCD
d0~d7: The numbers of the Arduino pins that are connected to the corresponding data pins on the LCD. d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using only the four data lines (d4, d5, d6, d7).

begin

Description

Specifies the dimensions (width and height) of the display.

Syntax

lcd.begin(int cols, int rows)

Parameters

cols: The number of columns that the display has
rows: The number of rows that the display has

Returns

None

clear

Description

Clears the LCD screen and positions the cursor in the upper-left corner.

Syntax

lcd.clear

Parameters

None

Returns

None

home

Description

Positions the cursor in the upper-left of the LCD. That is, use that location in outputting subsequent text to the display. To also clear the display, use the clear() function instead.

Syntax

lcd.home

Parameters

None

Returns

None

setCursor

Description

Positions the LCD cursor. That is, set the location at which subsequent text written to the LCD will be displayed.

Syntax

lcd.setCursor(unsigned char col, unsigned char row)

Parameters

col: The column at which to position the cursor (with 0 being the first column)
row: The row at which to position the cursor (with 0 being the first row)

Returns

None

write

Description

Writes a character to the LCD.

Syntax

lcd.write(unsigned char data)

Parameters

data: The character to write to the display

Returns

None

print

Description

Prints text to the LCD.

Syntax

lcd.print(val)

Parameters

val: The data to print (char, byte, int, long, or string)

Returns

None

cursor

Description

Displays the LCD cursor: An underscore (line) at the position to which the next character will be written.

Syntax

lcd.cursor()

Parameters

None

Returns

None

noCursor

Description

Hides the LCD cursor.

Syntax

lcd.noCursor()

Parameters

None

Returns

None

blink

Description

Displays the blinking LCD cursor. If used in combination with the cursor() function, the result will depend on the particular display.

Syntax

lcd.blink()

Parameters

None

Returns

None

noBlink

Description

Turns off the blinking LCD cursor.

Syntax

lcd.noBlink()

Parameters

None

Returns

None

display

Description

Turns on the LCD display, after it has been turned off with noDisplay(). This will restore the text (and cursor) that was on the display.

Syntax

lcd.display()

Parameters

None

Returns

None

noDisplay

Description

Turns off the LCD display, without losing the text currently shown on it.

Syntax

lcd.noDisplay()

Parameters

None

Returns

None

scrollDisplayLeft

Description

Scrolls the contents of the display (text and cursor) one space to the left.

Syntax

lcd.scrollDisplayLeft()

Parameters

None

Returns

None

scrollDisplayRight

Description

Scrolls the contents of the display (text and cursor) one space to the right.

Syntax

lcd.scrollDisplayRight()

Parameters

None

Returns

None

autoscroll

Description

Turns on automatic scrolling of the LCD.

Syntax

lcd.autoscroll()

Parameters

None

Returns

None

noAutoscroll

Description

Turns off automatic scrolling of the LCD.

Syntax

lcd.noAutoscroll()

Parameters

None

Returns

None

leftToRight

Description

Set the direction for text written to the LCD to left-to-right, the default.

Syntax

lcd.leftToRight()

Parameters

None

Returns

None

rightToLeft

Description

Set the direction for text written to the LCD to right-to-left (the default is left-to-right).

Syntax

lcd.rightToLeft()

Parameters

None

Returns

None


Example

This example displays "KURUMI" on an LCD with three control lines and four data lines.


        #include <Arduino.h>
        #include <liquidcrystal.h>
         
        LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
         
        void setup()
        {
          lcd.print("KURUMI");
        }
         
        void loop() {}