All right, so now we have finished one more step, and that is almost the end now where we need to
do is to handle the LCD display, screen the LCD correctly, handle the infrared sensor is correct handle.
Now we need the LCD screen.
So I'm going to include here include the liquid.
Dot h libro.
OK, so all the includes you, but at the very beginning of your program and then I'm going to add define
for each of us Dean which is a five and then you find LCD E, which is a four.
So you can get that from the previous section defined see the four being which is six.
And then we need also.
Five, six, seven.
Five, six, seven, which is been number seven here, eight and nine.
So I just took the previous defines that I had when I set up the LCD screen.
Well, make sure you have the pins that correspond to your circuit.
You can see we have quite a lot of defense here.
And I'm going here in the global scope to use liquid.
Crystal City and then but the different so of the Arab spin, the pin.
The and then the default.
He agreed to a new line.
The five.
And then the six.
And these seven.
All right, and then I'm going to go to the void setup function and do see so I can do this right here
and see that begin with 16 and two, because that's the configuration of our LCD display.
And now, well, we can just print whatever we want here in the switch.
So let's start with the button zero.
I'm going to LCD that sit.
Just so we have zero and zero and I'm going to LCG good brains, the command.
And also to avoid a case when, for example, the in here is shot.
So the text is shorter than one of the previous comment we could print on the first line.
I'm going to add a few empty spaces to clear the rest of the line LCG print.
Let's just add a few spaces like this.
So this is a real solution.
Instead of using a fluke and check the length of the current as a string and then add many spaces,
just add a few spaces if you know that it's not going to go bigger than this.
OK, sometimes you don't need to overcomplicate the solution.
OK, this is just fine for you.
And then LCD that sits cursor with soap Calon zero line one.
So the signal nine waybill to LCD that screens with full of elements.
And let's just count the number of characters one, two, three, four, five, six, seven, eight,
nine, 10, 11, 12, 13, 14, 15.
Let's just add another one.
So 16.
So we have all the line.
And if we had a previous character here, we just put a space instead.
All right.
So we have a case with the button zero.
We is do our action and then we print something on the LCD screen and then let's do the same for you.
So entity that sits just over zero and zero LCD screens.
Command.
A Saudi prince with a few.
Space.
And actually, because we are going to repeat that a lot, maybe I can try to use a function here,
it's a void print comment on Etsy.
We can't comment.
So what I'm going to do is to do this.
And remove the extra tabs, so print command as I get in command.
So I said the closer to zero zero a predicament, I print a few extra spaces to clean the rest of the
line.
So now I can call this year instead of that print comment on LCD with the comment and then said the
closer to zero one and then print this.
And actually I can do the same.
I can create another function void, let's say print action on LCD with this thing, the string that
I'm calling action and I'm going to do LCD set just saw zero one and LCD print action.
So not what I can do is just call this print action on LCD instead of.
I'm just going to copy this here.
So now it looks much better and what I can do is just use this for every other cases so I'm not going
to forward, and one, I'm going to bring the LCD or so on the first line.
And on the second line, I'm going to bring the action.
But this time is Tuggle.
Energy one, and let's make sure the characters are up to 16, so one, two, three, four, five,
six, seven, eight, nine, 10, 11, 12, 13, 14, 15, 16.
I have a few.
Extra species.
Now I can, but this also.
For the button to.
And let's to go to work, so that's the exact same thing forward and three together and three.
All right, and now the last thing we are going to do for this activity is to handle this.
And also the default of the switch.
So what we do in this function here, we simply want to clear the LCD screen.
So I'm going to do LCD.
That's clear.
And that's all there is to it, because with this button, we don't change anything for the edit is
we don't print anything on the LCD.
We just clear the SD.
So that's it.
LCD got clear, nothing more.
And then the default, which means that if you press a button that is not on the list, so you can choose
to ignore it.
But you can also choose to print some message on the LCD.
So let's do print command and we are going to bring the command as well.
And then we are going to screen.
So use let's use the print action on entity and let's use it to print.
Not recognized.
And let's count the number of characters one, two, three, four, five, six, seven, eight, nine,
10, 11, 12, 13, 14, 15, 16 driblets.
And an adult here.
Let's add some nuts.
Just to make it better.
OK.
I'm going to remove this.
I think we have done everything OK.
And as you can see, our I know is one hundred and twenty lines, that stands to be a really good program
that's just verified.
Once again.
All right, so let's check the code.
So at the beginning, we include the remote, I have remote liveried of liquid crystal library.
We use some defiance to define the pins for the LCD, the pins for the entities, the pin for the infrared
receiver, and then we use some design to map the different buttons on the remote control.
OK, we create some arrays for the entities.
We set up the density display screen.
Then we have a bunch of function to set up the mode for the entity to cover of all IDs, to toggle the
ads to one entity from the index using the arrays here.
And then one function to bring something on the LCD on the first line, to bring something on the single
line and then in the setup so you can see the setup is very small.
We initialize the sale, which actually we don't need anymore.
So I'm going to remove it.
So we initialize the infrared receiver.
We set up demotes for the 80s and we initialize the LCD display screen.
Very simple.
And then in the loop, what we do, we check if we have received some data from the infrared receiver,
if yes, we get the command, we get the data that we write from the infrared receiver and then we switch.
We simply check all the different keys that we can handle using the mapping for the different buttons
that we have previously done.
Then for each button, we do a different action for zero.
We pull off it is and then we print what we need on the LC for button one.
We toggle any one button to do with the correct index button three.
We took a three with the index to if we press this button, we clear the city and then if we press the
button that is not recognized, we just bring some kind of error message in the estimate.
All right.
I know this is the time to actually test the code on the.
Let's upload the.
Don't imploding, and now I am going to press on the button no one here just once you can see we have
here the code 12 for me and then toggle anyone.
And we took all the eligible and we put it on.
I'm going to press one once more and then we pull right off.
So I press it again, we put it on, then I press the number two four on the energy to a press.
Number three, we put it on the eighty three.
It's like this I can toggle the difference is OK.
And now if I press the number zero, as you can see power of all it is and we pull out of place, OK,
I can put on all the ideas we have one, two, three and then zero again.
Go off of any list.
OK, now if I press on the stop, what will happen?
As you can see, the LCD is no clear them.
All right, and this is also the solution of this debate using version two of the remote library and
also using key, as you can see, the simulation hunting.
So I have used the exact same code as before, just with a few modifications just for this library.
OK, so the functionalities are the same.
Just let's see what is different.
So first, as you can see with my designs of the buttons for the remote controller, I don't use the
same numbers.
OK, he I have not the numbers here and I use the hexadecimal notation for the numbers.
So starting with zero X and then the number I have right then in the global scope, I am also initializing
those two things here specific to version two.
And then as you can see, everything related to these are the LCD don't change.
OK, but one of these two Cetron, what you can see here on the print command on LCD, that's the same
thing that I am using along instead of it for the command.
OK, and then we continue to do the same thing in the loop.
Of course, we use the version two.
So I receive the decoder with the results here.
Don't forget the ampersand and then I receive that resume.
And also the difference here is that I use long instead of it.
OK, because individual three, the numbers we had with the commands, so with the data we got from
the library, the numbers were really quite small so we could stored them in an integer.
But with the addition to here, the value you are going to get, this can be quite big number.
And if you was an integer, the integer will overflow.
So that's why I'm using long.
So I'm using long to get the value here and I'm using long here also.
OK, because if, for example, I use in to here I send along the non will be cast as an int and then
we would have some problem because this would overflow right here so long and long and everything else
is the same.
So now I'm going to start the simulation and take a look here.
And let's press on some buttons, so button one, for example, you can see the right and these both
on and you can see toggle added one with the.
So as you can see, the code is a quite big number.
And so this is the code for one.
And as you can see here.
So this is the decimal representation.
And here this is the hexadecimal representation.
But both are the same number.
This is just a different way of representing.
And then so I can tell you what.
Again, OK, I can tell you two, three.
OK.
And then if I press on zero, look at the end here.
All the edges are pulled off.
And I have the message here of I can also press on the button here to clear the screen again, then
continue to toggle the LCD.
And if I press a button that is not recognized, which I have not defined in code, well, not recognized.
OK, so anybody not recognize only the button I have not and used with the switch to process the command.
All right.
That's the end of this activity.
So here, as you could see, it's a little bit more complex than what we have done before.
But this is a truly great exercise.
OK, if you manage to do it all by yourself, you will have made huge progress.
So what I encourage you to do is to come back to this activity in for a few days and do it all over
again from scratch just by yourself.
All right.
So that's the end of this activity and that's also the end of the section on the infrared remote control.