LiquidCrystal() function how to use?

I've read about function LiquidCrystal(rs, enable, d4, d5, d6, d7) and I can not understand why lcd is used in the code, if definition says nothing about it?

Could anyone explain me all those?

Have you looked at any of the examples in the LCD library ?

Basically you create an lcd object using parameters such as you quoted that tell the library how the LCD is connected. Then you can "print" to the lcd object and the library uses the parameters you gave it to output the correct signals on the relevant pins and the output appears on the LCD.

I can understand what you said. Tell me please then why definition of this function does not say like this: LiquidCrystal object(rs, enable, d4, d5, d6, d7);

You would normally create a global lcd object like this

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

which creates an object names lcd and defines the pins to be used. Then, in setup() you do this

 // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

Where have you

read about function LiquidCrystal(rs, enable, d4, d5, d6, d7)

OK, I say again. I understand that it should done like that but when I read discription of function LiquidCrystal(rs, enable, d4, d5, d6, d7) they does not say that I should refer to object lcd.

when I read discription of function LiquidCrystal(rs, enable, d4, d5, d6, d7)

Where ?

Here: https://www.arduino.cc/en/Reference/LiquidCrystalConstructor

I suspect that the syntax examples

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)

are expressed like that for simplicity (or it is simply a mistake), but the example code on the same page has the normal syntax and includes an object name

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

Or maybe
lcd.LiquidCrystal(rs, enable, d4, d5, d6, d7) and LiquidCrystal lcd(rs, enable, d4, d5, d6, d7) mean the same.

richardm55: Or maybe lcd.LiquidCrystal(rs, enable, d4, d5, d6, d7) and LiquidCrystal lcd(rs, enable, d4, d5, d6, d7) mean the same.

If you don't create a named object then you cannot use the LCD functions later in the program.

So you're saying that with syntax LiquidCrystal lcd(rs, enable, d4, d5, d6, d7); you create object lcd first. I thought that LiquidCrystal(rs, enable, d4, d5, d6, d7) was function so this LiquidCrystal lcd(rs, enable, d4, d5, d6, d7) does look like function rather.

richardm55: I've read about function LiquidCrystal(rs, enable, d4, d5, d6, d7) and I can not understand why lcd is used in the code, if definition says nothing about it?

Could anyone explain me all those?

In C/C++ you declare a variable by declaring type and name, such like:

  int value;
  long time;
  float voltage;

In C++ you cannot only declare variables, you also can declare objects. The type of an object is the name of a 'class'. The LiquidCrystal library codes a class named 'LiquidCrystal' (same name as the Library, as it is often with Arduino libraries).

So you declare objects like:

  className1 objectName1(); // declare an object without any initialization parameters
or
  className2 objectName2(parameter1, parameter2); // declare an object with two initialization parameters
or in your case
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // declare a LiquidCrystal  object with 6 pin numbers as parameters

After the object 'lcd' has been declared (and initialized with its parameters), it is ready to use, with function calls like:

  lcd.begin(16,2); // starts the LCD display controller working
  lcd.print("Some Text"); // display "Some Text"

Thank you so much. You've explained all this brilliantly, mate. I've really mistaken class with function. So that line was declaration of object lcd with some parameters in the class LiquidCrystal.

Thank you so much. You're star, mate.

richardm55:
So you’re saying that with syntax LiquidCrystal lcd(rs, enable, d4, d5, d6, d7); you create object lcd first.
I thought that LiquidCrystal(rs, enable, d4, d5, d6, d7) was function so
this LiquidCrystal lcd(rs, enable, d4, d5, d6, d7) does look like function rather.

I do not know what most of that means but until you declare (create) an object you cannot use it

LiquidCrystal   lcd(rs, enable, d4, d5, d6, d7)

tells the compiler to use the LiquidCrystal class to create an object named lcd using the supplied parameters. Note that the object can have any name (within reason) just like a variable and does not have to be named lcd. It would be illogical but it could just as easily be named Richard as in

LiquidCrystal   Richard(rs, enable, d4, d5, d6, d7)

Maybe the best thing to say is that it is a special function called constructor. The constructor constructs (instantiates) an object (an instance) of a certain class (type). In this case the class / type is LiquidCrystalDisplay.

Usually constructors are used like

LiquidCrystalDisplay lcd = new LiquidCrystalDisplay(12, 11, 5, 4, 3, 2);

but the below is also valid (and used in the Arduino examples all over the internet)

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

The first version creates a (dynamic) object on the heap, the second one a (static) object on the stack.

Thank you all for all very useful information