And now let's write the code to know what was the button that was pressed on the infrared remote control.
So here we are going to use the remote library that we have just installed before and you will see.
So we're going to use digital PIN number five.
The first one I'm going to do is define that's name AIPA and then receive in OK.
And this is digital PIN number five.
So make sure you use the correct pin if you have changed the pin to another one of these accordingly
and know when we are not going to directly use this with digital red digital.
Right.
Whatever we're going to use directly the library.
OK, which will handle the pin for us and to use the library.
Well, I'm going to write some instructions and there is nothing or I need to understand here is just
how to write the instructions.
So this is just some syntax you have to write so you can use the library.
OK, so I'm going first to do I receive like this so I r and R e c the lowercase.
OK, so this is the type.
This is the data type that is defined here in the library to create the object available that we can
use to receive and process the signal.
And I'm going to name it.
So the same but all lowercase, OK, and here I need to give one parameter frontages, which is the
number of the people like this with semicolon.
And then I need to also decode and here with an underscore results like this, you can see terms around
and let's go.
That does nothing really to understand.
That's just how you have to write.
OK, in the setup, what I'm going to do in the set.
So I'm going first to initialize cellular communication because we are going to print the results on
the same.
So.
That's initial sale, and then I need to use the receiver that I've created here, I received that enabled
I up in Ladies the I uppercase and then the eyes of a kitten in lowercase.
This will enable the with the library.
Again, why I use this because I have told you that it's better to use a meaningful name and this is
actually not a real meaningful name is just because well this is actually the typical example you can
find on the Internet.
So if you need to actually get more examples or get more help from the Internet, it's also sometimes
better to use the convention that everyone is using.
So everyone is using that.
I'm going to use that as well for this library.
And individual books are not the same and so is initialized with the three lines here in the loop.
I'm going to do if I'm going to take this, if I receive that decode and then I need to give so ampersand
results.
So this is a complaisant out of the scope of this schools.
But basically I give the reference to the results structure here.
You just need to know that you have to write this code like this.
And this is really similar to when we did, for example, if the label.
OK, this will just tell you if there are some results, if you can decode some results from DICENZO
and it will put the result inside the results variable that we have here.
So then what you can do is so let's do some that print and then get the results.
You can do results that value, OK, and this time No Ambersons and we do this.
And one thing that is important is after you have used decode.
So if you can do that here or after the sale, the printer doesn't matter.
You have to do so.
Do this again.
I'll receive that regime.
OK, whenever you decode the results, you have to resume after that so you can will continue for the
next rate.
And let's run that program.
OK, let's upload.
And don't go blowing, so I'm going to open the sale monitor, OK, which should not contain anything
now and I'm going to take the remote control over here and I'm just going to press on no.
So let's say No.
One.
OK, and you can see here we have the red ality.
That is whenever I send some data, whenever I press a button, you can see on my sensor I have the
ability to just tell that I have received something.
So maybe you will have that or not in your secret and you can see in the monitor.
So let's say press one again.
I have some number, rather big number.
If I keep pressing, I have a different number and I press to press one, two, three.
For example, I press the button plus the volume minus.
OK, you can see for each different button I have different values.
OK.
So if you have the results like this, this means that it's working for you and you also may not have
the same values as me, OK?
Each controller will send different numbers.
I'm going to explain that later.
So here we have some big numbers.
What I'm going to do, instead of just printing the results like that, I'm going to add X like this
in uppercase and this should turn blue.
What is that?
Basically, we sell the print and then I'm going to be able to print either the number like this, print
the number in hexadecimal.
So hexadecimal to make it simpler.
It's just another way to represent the number.
OK, so basically you have different ways of representing number.
For example, binary binary is just zero or one in the decimal system that we all know.
We have numbers from zero to nine in the habit of this.
Well, the number goes from zero to nine and then you have A, B, C, D, E, and so you have 16 numbers
and ABCDE and F our numbers after nine.
OK, so basically you will have that number or representation with stuff between zero and nine and eight
to F.
So let's upload the code again.
And this is actually will be more readable and let's say a monitor.
OK, I'm going to press zero again and I have the exact decimal number here.
OK, we've f f and you can see eye to eye by three, I press nine.
We have different numbers here in hexadecimal.
OK, I can press any button like to play button to go first button fastforward first Buckwald etc..
And if I keep pressing on the button, let's say keep pressing on any button you can see then I have
a lot of F's.
OK, so whenever you press the button, once you have one hit number, whenever you keep pressing on
the button, you have F F F.
So it means that you have pressed on the same button as before continuously and be careful because the
remote controller can be quite sensitive.
So sometimes you will press on the button twice.
OK, and again, this is because this is probably not the best quality ever.
So make sure that you just press once on the.
Once quick and sometimes when you press the button, so if I press too, I know that, OK, press to
multiple times, I know that this is the number four to OK and sometimes so it's not happening here.
But for other numbers, you may have some garbage data other than these are fair, but that's not a
problem because later on we are going to be able to tell exactly when we have this.
This is number two, for example, or when we have this.
OK, you can see I have some weird data here, for example, this is weird, but when we have this,
we know it's the play button.
So if we have this, we are going to ignore that value.
All right.
So now you are able to decode the signal you got from the infrared sensor with this code and you can
get each different button that you press.
You will get a different value here.
So each button of your remote controller will give you a different value.
And also each different controller may give you different values.
So the controller you have will probably give different values that the controller I have him again
here is the same code that I've written for Tinker.
So let's upload the code and you can see it should work.
Using the two point six, put one of that library, OK, this is the thing called the long link to open
the same monitor here and I'm going to press on the button, say zero to any button I can press.
OK, you can see we give us a different number in Hexa.
This if I keep pressing, you can see I have the f f f f f.
All right.
So it's the same thing as using the real controller.
But here.
No, this is important.
Let's see here.
I still have this monitor on my real secret.
I'm going to press number zero.
So number zero, I have F F 68, 97, the zero and have F the 30 S.F. So that's a different number.
OK, that's the exact same controller.
OK, this looks like the exact same controller, but we have different values.
OK, because as I told you, each controller.
OK, even the same ones.
OK, in the same kids, each controller, different hardware can give you different values.
So you are going to need to map the values depending on the controller you are actually using.
All right.
So that is how it works with the version two of the remote library.