WEBVTT

00:00.180 --> 00:05.520
All right, so now we have finished one more step, and that is almost the end now where we need to

00:05.520 --> 00:14.260
do is to handle the LCD display, screen the LCD correctly, handle the infrared sensor is correct handle.

00:14.280 --> 00:16.520
Now we need the LCD screen.

00:16.800 --> 00:21.210
So I'm going to include here include the liquid.

00:25.320 --> 00:26.610
Dot h libro.

00:26.880 --> 00:34.230
OK, so all the includes you, but at the very beginning of your program and then I'm going to add define

00:34.860 --> 00:47.370
for each of us Dean which is a five and then you find LCD E, which is a four.

00:47.370 --> 00:55.530
So you can get that from the previous section defined see the four being which is six.

00:55.680 --> 00:57.390
And then we need also.

00:58.760 --> 01:00.140
Five, six, seven.

01:01.920 --> 01:09.700
Five, six, seven, which is been number seven here, eight and nine.

01:10.860 --> 01:17.450
So I just took the previous defines that I had when I set up the LCD screen.

01:18.210 --> 01:21.490
Well, make sure you have the pins that correspond to your circuit.

01:21.750 --> 01:23.840
You can see we have quite a lot of defense here.

01:25.070 --> 01:28.880
And I'm going here in the global scope to use liquid.

01:30.670 --> 01:41.170
Crystal City and then but the different so of the Arab spin, the pin.

01:43.610 --> 01:45.770
The and then the default.

01:47.210 --> 01:48.710
He agreed to a new line.

01:50.750 --> 01:52.190
The five.

01:54.230 --> 01:55.760
And then the six.

01:57.270 --> 01:58.410
And these seven.

02:01.680 --> 02:10.610
All right, and then I'm going to go to the void setup function and do see so I can do this right here

02:10.650 --> 02:19.680
and see that begin with 16 and two, because that's the configuration of our LCD display.

02:20.340 --> 02:25.590
And now, well, we can just print whatever we want here in the switch.

02:25.950 --> 02:28.300
So let's start with the button zero.

02:28.530 --> 02:31.350
I'm going to LCD that sit.

02:33.070 --> 02:41.710
Just so we have zero and zero and I'm going to LCG good brains, the command.

02:43.220 --> 02:47.600
And also to avoid a case when, for example, the in here is shot.

02:48.170 --> 02:53.210
So the text is shorter than one of the previous comment we could print on the first line.

02:53.810 --> 02:59.170
I'm going to add a few empty spaces to clear the rest of the line LCG print.

02:59.510 --> 03:03.170
Let's just add a few spaces like this.

03:03.900 --> 03:05.240
So this is a real solution.

03:05.240 --> 03:10.970
Instead of using a fluke and check the length of the current as a string and then add many spaces,

03:11.300 --> 03:16.560
just add a few spaces if you know that it's not going to go bigger than this.

03:16.590 --> 03:20.630
OK, sometimes you don't need to overcomplicate the solution.

03:20.660 --> 03:22.230
OK, this is just fine for you.

03:22.340 --> 03:30.670
And then LCD that sits cursor with soap Calon zero line one.

03:30.680 --> 03:40.240
So the signal nine waybill to LCD that screens with full of elements.

03:42.780 --> 03:49.380
And let's just count the number of characters one, two, three, four, five, six, seven, eight,

03:49.380 --> 03:54.100
nine, 10, 11, 12, 13, 14, 15.

03:54.450 --> 03:55.980
Let's just add another one.

03:55.990 --> 03:57.060
So 16.

03:57.060 --> 03:58.470
So we have all the line.

03:58.770 --> 04:02.490
And if we had a previous character here, we just put a space instead.

04:03.150 --> 04:03.540
All right.

04:03.540 --> 04:05.520
So we have a case with the button zero.

04:05.730 --> 04:15.340
We is do our action and then we print something on the LCD screen and then let's do the same for you.

04:15.900 --> 04:23.520
So entity that sits just over zero and zero LCD screens.

04:25.500 --> 04:26.160
Command.

04:27.750 --> 04:30.660
A Saudi prince with a few.

04:31.890 --> 04:32.470
Space.

04:33.540 --> 04:39.690
And actually, because we are going to repeat that a lot, maybe I can try to use a function here,

04:39.720 --> 04:46.570
it's a void print comment on Etsy.

04:46.830 --> 04:49.310
We can't comment.

04:50.850 --> 04:55.140
So what I'm going to do is to do this.

04:58.240 --> 05:05.700
And remove the extra tabs, so print command as I get in command.

05:05.740 --> 05:13.060
So I said the closer to zero zero a predicament, I print a few extra spaces to clean the rest of the

05:13.060 --> 05:13.360
line.

05:13.750 --> 05:23.380
So now I can call this year instead of that print comment on LCD with the comment and then said the

05:23.380 --> 05:27.130
closer to zero one and then print this.

05:27.130 --> 05:28.630
And actually I can do the same.

05:28.630 --> 05:36.960
I can create another function void, let's say print action on LCD with this thing, the string that

05:36.970 --> 05:48.100
I'm calling action and I'm going to do LCD set just saw zero one and LCD print action.

05:49.640 --> 05:56.720
So not what I can do is just call this print action on LCD instead of.

05:57.920 --> 05:59.570
I'm just going to copy this here.

06:05.210 --> 06:14.210
So now it looks much better and what I can do is just use this for every other cases so I'm not going

06:14.210 --> 06:19.360
to forward, and one, I'm going to bring the LCD or so on the first line.

06:19.370 --> 06:21.770
And on the second line, I'm going to bring the action.

06:22.040 --> 06:24.170
But this time is Tuggle.

06:25.930 --> 06:33.130
Energy one, and let's make sure the characters are up to 16, so one, two, three, four, five,

06:33.130 --> 06:40.550
six, seven, eight, nine, 10, 11, 12, 13, 14, 15, 16.

06:41.020 --> 06:42.070
I have a few.

06:43.250 --> 06:44.210
Extra species.

06:45.170 --> 06:48.080
Now I can, but this also.

06:50.550 --> 06:51.960
For the button to.

06:53.590 --> 07:01.810
And let's to go to work, so that's the exact same thing forward and three together and three.

07:02.930 --> 07:10.730
All right, and now the last thing we are going to do for this activity is to handle this.

07:12.300 --> 07:14.290
And also the default of the switch.

07:14.310 --> 07:20.760
So what we do in this function here, we simply want to clear the LCD screen.

07:20.770 --> 07:22.020
So I'm going to do LCD.

07:22.050 --> 07:24.150
That's clear.

07:24.570 --> 07:30.030
And that's all there is to it, because with this button, we don't change anything for the edit is

07:30.330 --> 07:32.400
we don't print anything on the LCD.

07:32.400 --> 07:33.870
We just clear the SD.

07:33.950 --> 07:34.590
So that's it.

07:34.650 --> 07:36.480
LCD got clear, nothing more.

07:37.050 --> 07:44.970
And then the default, which means that if you press a button that is not on the list, so you can choose

07:44.970 --> 07:46.390
to ignore it.

07:46.630 --> 07:51.540
But you can also choose to print some message on the LCD.

07:51.600 --> 07:57.080
So let's do print command and we are going to bring the command as well.

07:57.420 --> 07:58.550
And then we are going to screen.

07:58.560 --> 08:03.510
So use let's use the print action on entity and let's use it to print.

08:04.380 --> 08:06.300
Not recognized.

08:09.150 --> 08:14.550
And let's count the number of characters one, two, three, four, five, six, seven, eight, nine,

08:14.550 --> 08:20.310
10, 11, 12, 13, 14, 15, 16 driblets.

08:20.460 --> 08:21.300
And an adult here.

08:22.900 --> 08:24.360
Let's add some nuts.

08:26.880 --> 08:28.270
Just to make it better.

08:28.440 --> 08:28.910
OK.

08:30.400 --> 08:33.080
I'm going to remove this.

08:33.100 --> 08:36.090
I think we have done everything OK.

08:37.260 --> 08:44.010
And as you can see, our I know is one hundred and twenty lines, that stands to be a really good program

08:44.370 --> 08:45.690
that's just verified.

08:46.050 --> 08:47.220
Once again.

08:50.190 --> 08:52.030
All right, so let's check the code.

08:52.050 --> 08:58.110
So at the beginning, we include the remote, I have remote liveried of liquid crystal library.

08:58.680 --> 09:06.120
We use some defiance to define the pins for the LCD, the pins for the entities, the pin for the infrared

09:06.330 --> 09:14.560
receiver, and then we use some design to map the different buttons on the remote control.

09:14.660 --> 09:17.730
OK, we create some arrays for the entities.

09:17.730 --> 09:19.800
We set up the density display screen.

09:20.290 --> 09:27.030
Then we have a bunch of function to set up the mode for the entity to cover of all IDs, to toggle the

09:27.040 --> 09:31.140
ads to one entity from the index using the arrays here.

09:32.880 --> 09:38.230
And then one function to bring something on the LCD on the first line, to bring something on the single

09:38.270 --> 09:42.890
line and then in the setup so you can see the setup is very small.

09:43.530 --> 09:46.820
We initialize the sale, which actually we don't need anymore.

09:46.830 --> 09:47.910
So I'm going to remove it.

09:48.510 --> 09:51.040
So we initialize the infrared receiver.

09:51.720 --> 09:56.730
We set up demotes for the 80s and we initialize the LCD display screen.

09:56.970 --> 09:57.760
Very simple.

09:58.320 --> 10:04.880
And then in the loop, what we do, we check if we have received some data from the infrared receiver,

10:05.220 --> 10:12.630
if yes, we get the command, we get the data that we write from the infrared receiver and then we switch.

10:13.080 --> 10:19.770
We simply check all the different keys that we can handle using the mapping for the different buttons

10:19.770 --> 10:21.150
that we have previously done.

10:21.660 --> 10:24.640
Then for each button, we do a different action for zero.

10:24.640 --> 10:32.040
We pull off it is and then we print what we need on the LC for button one.

10:32.040 --> 10:39.210
We toggle any one button to do with the correct index button three.

10:39.210 --> 10:48.240
We took a three with the index to if we press this button, we clear the city and then if we press the

10:48.240 --> 10:55.320
button that is not recognized, we just bring some kind of error message in the estimate.

10:55.650 --> 10:56.130
All right.

10:56.130 --> 11:01.200
I know this is the time to actually test the code on the.

11:01.530 --> 11:03.060
Let's upload the.

11:05.840 --> 11:15.110
Don't imploding, and now I am going to press on the button no one here just once you can see we have

11:15.110 --> 11:18.760
here the code 12 for me and then toggle anyone.

11:18.770 --> 11:21.440
And we took all the eligible and we put it on.

11:21.440 --> 11:25.580
I'm going to press one once more and then we pull right off.

11:25.910 --> 11:32.180
So I press it again, we put it on, then I press the number two four on the energy to a press.

11:32.180 --> 11:34.930
Number three, we put it on the eighty three.

11:35.180 --> 11:39.770
It's like this I can toggle the difference is OK.

11:40.190 --> 11:48.500
And now if I press the number zero, as you can see power of all it is and we pull out of place, OK,

11:48.560 --> 11:53.180
I can put on all the ideas we have one, two, three and then zero again.

11:53.900 --> 11:55.650
Go off of any list.

11:55.940 --> 12:00.350
OK, now if I press on the stop, what will happen?

12:00.860 --> 12:03.850
As you can see, the LCD is no clear them.

12:05.890 --> 12:13.960
All right, and this is also the solution of this debate using version two of the remote library and

12:13.960 --> 12:17.340
also using key, as you can see, the simulation hunting.

12:18.010 --> 12:24.740
So I have used the exact same code as before, just with a few modifications just for this library.

12:24.760 --> 12:27.180
OK, so the functionalities are the same.

12:27.520 --> 12:29.680
Just let's see what is different.

12:29.710 --> 12:36.850
So first, as you can see with my designs of the buttons for the remote controller, I don't use the

12:36.850 --> 12:38.130
same numbers.

12:38.140 --> 12:45.050
OK, he I have not the numbers here and I use the hexadecimal notation for the numbers.

12:45.070 --> 12:53.650
So starting with zero X and then the number I have right then in the global scope, I am also initializing

12:53.650 --> 12:57.040
those two things here specific to version two.

12:57.490 --> 13:03.190
And then as you can see, everything related to these are the LCD don't change.

13:03.220 --> 13:11.710
OK, but one of these two Cetron, what you can see here on the print command on LCD, that's the same

13:11.710 --> 13:16.610
thing that I am using along instead of it for the command.

13:16.630 --> 13:20.170
OK, and then we continue to do the same thing in the loop.

13:20.170 --> 13:22.620
Of course, we use the version two.

13:22.630 --> 13:26.470
So I receive the decoder with the results here.

13:26.500 --> 13:30.970
Don't forget the ampersand and then I receive that resume.

13:31.540 --> 13:35.930
And also the difference here is that I use long instead of it.

13:36.250 --> 13:43.240
OK, because individual three, the numbers we had with the commands, so with the data we got from

13:43.240 --> 13:49.240
the library, the numbers were really quite small so we could stored them in an integer.

13:49.480 --> 13:55.060
But with the addition to here, the value you are going to get, this can be quite big number.

13:55.060 --> 13:58.900
And if you was an integer, the integer will overflow.

13:59.620 --> 14:01.320
So that's why I'm using long.

14:01.330 --> 14:05.280
So I'm using long to get the value here and I'm using long here also.

14:05.490 --> 14:12.550
OK, because if, for example, I use in to here I send along the non will be cast as an int and then

14:12.580 --> 14:19.540
we would have some problem because this would overflow right here so long and long and everything else

14:19.690 --> 14:20.230
is the same.

14:20.650 --> 14:24.850
So now I'm going to start the simulation and take a look here.

14:26.270 --> 14:33.020
And let's press on some buttons, so button one, for example, you can see the right and these both

14:33.020 --> 14:36.140
on and you can see toggle added one with the.

14:37.130 --> 14:39.490
So as you can see, the code is a quite big number.

14:39.680 --> 14:42.370
And so this is the code for one.

14:42.380 --> 14:44.130
And as you can see here.

14:44.570 --> 14:47.390
So this is the decimal representation.

14:47.600 --> 14:51.410
And here this is the hexadecimal representation.

14:51.410 --> 14:53.760
But both are the same number.

14:54.040 --> 14:56.840
This is just a different way of representing.

14:56.840 --> 14:59.100
And then so I can tell you what.

14:59.180 --> 15:03.640
Again, OK, I can tell you two, three.

15:03.690 --> 15:04.290
OK.

15:04.430 --> 15:09.380
And then if I press on zero, look at the end here.

15:10.010 --> 15:12.200
All the edges are pulled off.

15:12.200 --> 15:20.720
And I have the message here of I can also press on the button here to clear the screen again, then

15:20.720 --> 15:22.940
continue to toggle the LCD.

15:23.570 --> 15:30.310
And if I press a button that is not recognized, which I have not defined in code, well, not recognized.

15:30.390 --> 15:39.230
OK, so anybody not recognize only the button I have not and used with the switch to process the command.

15:39.680 --> 15:40.190
All right.

15:40.190 --> 15:42.190
That's the end of this activity.

15:42.410 --> 15:49.030
So here, as you could see, it's a little bit more complex than what we have done before.

15:49.340 --> 15:51.510
But this is a truly great exercise.

15:51.530 --> 15:56.440
OK, if you manage to do it all by yourself, you will have made huge progress.

15:56.780 --> 16:03.320
So what I encourage you to do is to come back to this activity in for a few days and do it all over

16:03.320 --> 16:05.770
again from scratch just by yourself.

16:05.930 --> 16:06.310
All right.

16:06.320 --> 16:13.220
So that's the end of this activity and that's also the end of the section on the infrared remote control.
