Let's now write the code to just print something simple on the LCD screen.
So first of all, we are going to use a define for each of the pin that we need.
Okay, so define I'm going to put LCD.
So we will need the S pin, which is pin number eight four.
And then define LCD pin, which is pin number eight five.
Then we need the pins from So LCD, the four pin, which is two and we will need D4 d5 D6 and D7.
So let's change that 567, which are PIN number two, three, four and five.
Okay.
So we have six pins that we need in our program.
Then to initialize the LCD screen, we will need first to include the liquid crystal.
Libraries.
Liquid crystal dot H.
Like this with angled brackets.
Then we can add so not in the void setup, but in the global scope here.
Liquid crystal.
Let's name it LCD and we are going to initialize it by providing the different pins here in the order.
So R.
S and then E.
And then D4.
And then I'm going to go to a new line here.
Let's put D5.
Let's align this here.
The six and the seven.
So we have our LCD object.
And now to finish with the initialization in the void setup, we do LCD dot begin with 16 and two.
So we are going to use 16 columns and two lines, which is basically what the screen has.
And then well, if you want to print something on the screen, you just do LCD dot print and let's say
starting with dot, dot, dot, let's say we want to print that at the beginning.
So let's make sure that the board is connected.
Let's upload the code.
I forgot here.
So.
Well, the error is here, but I forgot here.
A comma.
Let's run again.
Okay.
And this is what you can see here.
So maybe you will not have anything is because you need to move the potentiometer until you find you
can see here, until you find the correct angle for the potentiometer to correctly calibrate the screen.
So here it looks good.
Okay.
We have starting correctly displayed.
So make sure that for the first time you actually move the potentiometer so that you can see something.
Once you see something, then we can go further.
Okay.
And now, for example, if you want to clear the screen, let's say we do delay 2000.
So we want to print for two seconds and then we do LCD dot clear.
This is going to print starting and after two seconds it's going to clear the entire screen.
Let's upload this.
So you can see starting and after two seconds, the text is gone.
All right.
So let's actually comment that.
And one other thing is that you can actually play with the cursor.
So by default, the cursor is going to be at zero and zero.
So you can do LCD dot set cursor and by default, it's going to be here zero and zero.
Here you can see you have 16 by two.
So if you put, for example, three, that's going to be on the third column.
If you put one here, that's going to be on the second line.
Okay.
So we start to count at zero.
So you can go from 0 to 15 here and 0 to 1 here.
And so here we're going to print starting, but let's see where.
So upload.
And you can see we print starting on the second line, starting from the fourth column.
Okay.
Because this is the three and one.
So that's second line, fourth column.
And so every time we want to change the cursor, you just do LCD set cursor and then you start to print
something and that's going to start to print from where the cursor is.
Okay.
So basically that's pretty much it.
First you initialize the LCD.
You do LCD dot begin with 16 by two and then we've set cursor.
You can set the cursor to a different place with print.
You print some text and LCD clear is very useful.
So you can also clear the entire screen before you write something.