WEBVTT

00:00.080 --> 00:05.690
Let's now write the code to just print something simple on the LCD screen.

00:05.690 --> 00:11.110
So first of all, we are going to use a define for each of the pin that we need.

00:11.120 --> 00:14.630
Okay, so define I'm going to put LCD.

00:14.630 --> 00:20.450
So we will need the S pin, which is pin number eight four.

00:20.450 --> 00:28.190
And then define LCD pin, which is pin number eight five.

00:28.220 --> 00:41.870
Then we need the pins from So LCD, the four pin, which is two and we will need D4 d5 D6 and D7.

00:41.870 --> 00:51.110
So let's change that 567, which are PIN number two, three, four and five.

00:51.140 --> 00:51.380
Okay.

00:51.380 --> 00:55.040
So we have six pins that we need in our program.

00:55.280 --> 01:04.010
Then to initialize the LCD screen, we will need first to include the liquid crystal.

01:05.580 --> 01:06.310
Libraries.

01:06.480 --> 01:08.290
Liquid crystal dot H.

01:08.310 --> 01:10.390
Like this with angled brackets.

01:10.410 --> 01:15.390
Then we can add so not in the void setup, but in the global scope here.

01:15.660 --> 01:18.690
Liquid crystal.

01:18.930 --> 01:26.520
Let's name it LCD and we are going to initialize it by providing the different pins here in the order.

01:26.520 --> 01:27.520
So R.

01:27.570 --> 01:29.550
S and then E.

01:30.970 --> 01:32.950
And then D4.

01:34.300 --> 01:37.780
And then I'm going to go to a new line here.

01:38.080 --> 01:39.970
Let's put D5.

01:40.570 --> 01:42.370
Let's align this here.

01:43.960 --> 01:47.830
The six and the seven.

01:50.240 --> 01:53.480
So we have our LCD object.

01:53.780 --> 02:02.560
And now to finish with the initialization in the void setup, we do LCD dot begin with 16 and two.

02:02.570 --> 02:09.770
So we are going to use 16 columns and two lines, which is basically what the screen has.

02:09.770 --> 02:18.200
And then well, if you want to print something on the screen, you just do LCD dot print and let's say

02:18.830 --> 02:25.220
starting with dot, dot, dot, let's say we want to print that at the beginning.

02:26.650 --> 02:29.770
So let's make sure that the board is connected.

02:29.770 --> 02:32.020
Let's upload the code.

02:33.310 --> 02:34.300
I forgot here.

02:34.300 --> 02:34.600
So.

02:34.600 --> 02:37.150
Well, the error is here, but I forgot here.

02:37.420 --> 02:38.230
A comma.

02:40.290 --> 02:41.490
Let's run again.

02:43.620 --> 02:43.890
Okay.

02:43.890 --> 02:45.750
And this is what you can see here.

02:45.750 --> 02:52.410
So maybe you will not have anything is because you need to move the potentiometer until you find you

02:52.410 --> 02:59.520
can see here, until you find the correct angle for the potentiometer to correctly calibrate the screen.

03:01.170 --> 03:04.490
So here it looks good.

03:04.500 --> 03:04.770
Okay.

03:04.770 --> 03:07.680
We have starting correctly displayed.

03:07.680 --> 03:12.870
So make sure that for the first time you actually move the potentiometer so that you can see something.

03:12.870 --> 03:15.420
Once you see something, then we can go further.

03:16.150 --> 03:16.480
Okay.

03:16.480 --> 03:22.180
And now, for example, if you want to clear the screen, let's say we do delay 2000.

03:22.180 --> 03:27.310
So we want to print for two seconds and then we do LCD dot clear.

03:27.580 --> 03:33.130
This is going to print starting and after two seconds it's going to clear the entire screen.

03:33.130 --> 03:34.450
Let's upload this.

03:37.000 --> 03:43.000
So you can see starting and after two seconds, the text is gone.

03:43.210 --> 03:43.660
All right.

03:43.660 --> 03:46.990
So let's actually comment that.

03:47.590 --> 03:50.740
And one other thing is that you can actually play with the cursor.

03:50.740 --> 03:54.460
So by default, the cursor is going to be at zero and zero.

03:54.460 --> 04:02.770
So you can do LCD dot set cursor and by default, it's going to be here zero and zero.

04:03.220 --> 04:05.470
Here you can see you have 16 by two.

04:05.500 --> 04:09.520
So if you put, for example, three, that's going to be on the third column.

04:09.520 --> 04:13.690
If you put one here, that's going to be on the second line.

04:13.690 --> 04:13.900
Okay.

04:13.900 --> 04:15.850
So we start to count at zero.

04:15.850 --> 04:19.930
So you can go from 0 to 15 here and 0 to 1 here.

04:20.170 --> 04:23.820
And so here we're going to print starting, but let's see where.

04:23.830 --> 04:25.420
So upload.

04:27.590 --> 04:34.130
And you can see we print starting on the second line, starting from the fourth column.

04:34.170 --> 04:34.350
Okay.

04:34.370 --> 04:36.440
Because this is the three and one.

04:36.440 --> 04:38.810
So that's second line, fourth column.

04:38.930 --> 04:45.410
And so every time we want to change the cursor, you just do LCD set cursor and then you start to print

04:45.410 --> 04:49.730
something and that's going to start to print from where the cursor is.

04:50.030 --> 04:50.450
Okay.

04:50.450 --> 04:51.920
So basically that's pretty much it.

04:51.920 --> 04:53.990
First you initialize the LCD.

04:54.020 --> 04:59.020
You do LCD dot begin with 16 by two and then we've set cursor.

04:59.030 --> 05:01.710
You can set the cursor to a different place with print.

05:01.730 --> 05:05.060
You print some text and LCD clear is very useful.

05:05.060 --> 05:09.620
So you can also clear the entire screen before you write something.
