All right.
And now let's use the remote library.
But this time, the version three.
So why did I start with version 2.6.1, and then I'm going to use version three.
Well, actually, for two reasons.
First, most of the examples in code you will find on the Internet are using the version two.
And so if you find a different code that is on version two, you know how it works.
And the second version also is because what you are going to see that on Tinker code.
Well, Tinker Cat only uses the version two.
And the thing is, we can't update the libraries on Tinker.
So on the original idea, we are going to do that.
We can change the library, we can change the version, we can change everything.
We have the complete control on Tinker that you don't have the control of which library in which version
of the library is installed.
So Tinker, you can only use that code.
So now what I'm going to do, I'm going to so copy all the code and create a new file here.
Let's paste the code and this is where we are going to use the version three of the library and to be
able to use the version three, I'm going to go to tools, manage libraries.
Or you can see here it updates the list and then I'm going to go to air remote.
And find the library.
So we have version 2.6.1.
So we are going to.
So what you can do is click on update or choose the version here.
So I'm going to choose the latest version.
If you click on update, that's going to do the same.
So again, for me, the latest version here is 3.0.3.
For you.
It might be higher, so you might want to just take the latest version and if it doesn't work, come
back to this version or even the 2.6.1, but this should work for you.
Okay, so let's install this.
And you can see now we have installed with version 3.0.3, which is a new version.
And this version actually has breaking changes with the version two, which means that the code here
would not just work like this, you will need to modify it.
And now we're using the version three well, because it's simply usually better to update your libraries
and to use the latest available version, which should be more stable with better functionalities,
better performance, etc..
So now what happens if I try to compile this code?
So let's name it remote and V three.
Okay.
So as you can see here, we don't have any problem for compilation.
So let's try to just upload the code and see what it does.
Okay, so now I'm going to open the side monitor, so make sure you upload the new code.
Okay?
Make sure you don't just verify, but that you upload.
Let's open a site and monitor and.
Oh, whoa, whoa.
What is that?
We have a lot of errors.
The function decode result is deprecated and may not work as expected.
Just use decode without any parameter and well, it's kind of so it's not working.
If I press some button, well, that's not going to work.
We have a lot of error messages and that is because we are using the code for the version two, but
using the version three.
So for some reason it's still compiles, but then you have a lot of errors in the style monitor.
So for the version three, we need to change completely the code.
I'm going to remove all of that.
And this also.
So I keep this.
I begin and I keep, of course, the defined for the pin.
The name of the library is the same, but now things are different.
So for the version three, you don't have anything to do in the global scope you are just going to do
Here I are receiver, so I uppercase and then are lowercase and then receiver with uppercase dot begin
and using the pin here.
Air receivers like this that begin with the pin and this will initialize the library and the sensor.
And then in the void loop we are going to do if.
I also.
Same here.
If air receiver does decode, but this time we don't have anything in decode.
Then when we can do is air receiver dot resume just like we did before.
But now we use our receiver just like this.
This is included in the library directly.
So if we use the include when we write this, Arduino is going to find out what is that and then let's
do some sale, let's print in and to get the results you will do I r receiver dot decoded i r data.
So here I r is a case.
Make sure you use the correct case because the case is very important here.
It's case sensitive dot.
So we have two ways of getting the data now decoded.
Wrong data with, let's say, X.
So we are going to print the decoded raw data with hexadecimal just like before.
And we can also do sale dot print with i.
R.
Receiver Dot decoded.
I r data dot com and this will actually give us a small number that is much easier to understand and
much easier to control.
So let's bring the two and I'm just going to add the print and then we've three dashes.
Okay?
So every time we read something, we can have three dashes to separate the results we get.
And now let's run that code and let's upload it directly.
And let's open the second monitor.
And now we should not have any error.
So I'm going to press any button and you can see when I press the button, I have an Exodus email result,
which is also different from the one we had with version two.
And we have second is a command.
So if I press zero, I get this hexadecimal and the command 22.
If I press one here, I get 12, I press two, I get 24, I press the let's say the on off button,
I get 69, I press the play button, I get 64.
So you get the hexadecimal value.
If you have zero, it means that you have pressed the same button twice and then you also get a value
that is actually easier to read and that is the value we are going to use.
So from now on we are going to use the command that we get from the library.
So as you can see, the version three of the library is an improved version.
It's going to work better and we have a better data to handle.
All right.
And again, the code here, you don't need to really understand.
Just know that you have to write this and then that you have to write this in order to get the information
using the library.
And now let's try to see what will happen if I try to put this code on.
So I'm going to copy the code here.
The code we have just used and put it on, think again.
So now we are trying to use the version three.
Let's start the simulation.
And you can see we have some arrows.
So what is the arrow in function void setup?
I receiver was not declared in the scope so I r receiver.
So here the line is not necessarily the correct one.
This is that 1ir receiver is not known in the library.
And why is that?
Is because Tinker uses the version two of the library.
So the I r receiver that is in version three is not known in version two.
So if you use Tinker just here, this is the code for version two that's going to work.
So if you use Tinker Cat, just use version two.
And if you use your Arduino ID, well, I recommend you use version three.
And for the following of this section, I'm going to keep using the version three of the library for
the Arduino ID, but if you are following the course with Tinker Cat, well that's not really a problem
because the code here, I'm not going to add anything else in that code.
We are going to add code outside of the remote functionality.
So this is all the code you need to get the sensor to work.
So if you are using version two and I'm using version three, just modify the code for receiving the
data with the remote controller and then everything else will be the same.