WEBVTT

00:00.270 --> 00:00.600
All right.

00:00.600 --> 00:03.810
And now let's use the remote library.

00:03.810 --> 00:06.120
But this time, the version three.

00:06.300 --> 00:11.460
So why did I start with version 2.6.1, and then I'm going to use version three.

00:11.460 --> 00:13.590
Well, actually, for two reasons.

00:13.710 --> 00:19.170
First, most of the examples in code you will find on the Internet are using the version two.

00:19.260 --> 00:24.840
And so if you find a different code that is on version two, you know how it works.

00:24.840 --> 00:29.190
And the second version also is because what you are going to see that on Tinker code.

00:29.280 --> 00:32.240
Well, Tinker Cat only uses the version two.

00:32.250 --> 00:36.050
And the thing is, we can't update the libraries on Tinker.

00:36.450 --> 00:40.050
So on the original idea, we are going to do that.

00:40.080 --> 00:43.740
We can change the library, we can change the version, we can change everything.

00:43.740 --> 00:49.800
We have the complete control on Tinker that you don't have the control of which library in which version

00:49.800 --> 00:51.360
of the library is installed.

00:51.360 --> 00:53.980
So Tinker, you can only use that code.

00:54.000 --> 01:00.270
So now what I'm going to do, I'm going to so copy all the code and create a new file here.

01:01.770 --> 01:08.580
Let's paste the code and this is where we are going to use the version three of the library and to be

01:08.580 --> 01:13.230
able to use the version three, I'm going to go to tools, manage libraries.

01:16.040 --> 01:21.110
Or you can see here it updates the list and then I'm going to go to air remote.

01:23.520 --> 01:24.810
And find the library.

01:24.810 --> 01:27.210
So we have version 2.6.1.

01:27.210 --> 01:28.620
So we are going to.

01:28.650 --> 01:31.980
So what you can do is click on update or choose the version here.

01:31.980 --> 01:34.250
So I'm going to choose the latest version.

01:34.260 --> 01:36.810
If you click on update, that's going to do the same.

01:36.810 --> 01:41.040
So again, for me, the latest version here is 3.0.3.

01:41.040 --> 01:41.460
For you.

01:41.460 --> 01:48.600
It might be higher, so you might want to just take the latest version and if it doesn't work, come

01:48.600 --> 01:53.160
back to this version or even the 2.6.1, but this should work for you.

01:53.400 --> 01:55.110
Okay, so let's install this.

01:55.110 --> 02:02.130
And you can see now we have installed with version 3.0.3, which is a new version.

02:02.250 --> 02:07.710
And this version actually has breaking changes with the version two, which means that the code here

02:07.710 --> 02:10.470
would not just work like this, you will need to modify it.

02:11.160 --> 02:17.100
And now we're using the version three well, because it's simply usually better to update your libraries

02:17.100 --> 02:22.980
and to use the latest available version, which should be more stable with better functionalities,

02:22.980 --> 02:24.990
better performance, etc..

02:25.080 --> 02:28.890
So now what happens if I try to compile this code?

02:28.890 --> 02:33.540
So let's name it remote and V three.

02:36.600 --> 02:36.840
Okay.

02:36.840 --> 02:41.220
So as you can see here, we don't have any problem for compilation.

02:41.520 --> 02:44.580
So let's try to just upload the code and see what it does.

02:46.270 --> 02:49.620
Okay, so now I'm going to open the side monitor, so make sure you upload the new code.

02:49.630 --> 02:49.930
Okay?

02:50.170 --> 02:52.710
Make sure you don't just verify, but that you upload.

02:52.720 --> 02:55.060
Let's open a site and monitor and.

02:55.060 --> 02:55.960
Oh, whoa, whoa.

02:55.960 --> 02:57.070
What is that?

02:57.550 --> 02:59.580
We have a lot of errors.

02:59.590 --> 03:04.480
The function decode result is deprecated and may not work as expected.

03:04.480 --> 03:10.600
Just use decode without any parameter and well, it's kind of so it's not working.

03:10.600 --> 03:13.330
If I press some button, well, that's not going to work.

03:13.330 --> 03:19.060
We have a lot of error messages and that is because we are using the code for the version two, but

03:19.060 --> 03:20.560
using the version three.

03:20.710 --> 03:26.140
So for some reason it's still compiles, but then you have a lot of errors in the style monitor.

03:26.170 --> 03:30.010
So for the version three, we need to change completely the code.

03:30.020 --> 03:32.470
I'm going to remove all of that.

03:33.960 --> 03:35.850
And this also.

03:35.970 --> 03:37.040
So I keep this.

03:37.070 --> 03:40.950
I begin and I keep, of course, the defined for the pin.

03:41.070 --> 03:46.000
The name of the library is the same, but now things are different.

03:46.020 --> 03:50.790
So for the version three, you don't have anything to do in the global scope you are just going to do

03:50.820 --> 04:01.740
Here I are receiver, so I uppercase and then are lowercase and then receiver with uppercase dot begin

04:02.160 --> 04:04.710
and using the pin here.

04:05.940 --> 04:12.660
Air receivers like this that begin with the pin and this will initialize the library and the sensor.

04:12.780 --> 04:15.510
And then in the void loop we are going to do if.

04:16.610 --> 04:17.440
I also.

04:17.450 --> 04:18.350
Same here.

04:19.810 --> 04:25.830
If air receiver does decode, but this time we don't have anything in decode.

04:27.670 --> 04:35.440
Then when we can do is air receiver dot resume just like we did before.

04:35.440 --> 04:38.560
But now we use our receiver just like this.

04:39.250 --> 04:41.410
This is included in the library directly.

04:41.410 --> 04:48.670
So if we use the include when we write this, Arduino is going to find out what is that and then let's

04:48.670 --> 05:01.420
do some sale, let's print in and to get the results you will do I r receiver dot decoded i r data.

05:01.870 --> 05:03.760
So here I r is a case.

05:03.760 --> 05:09.010
Make sure you use the correct case because the case is very important here.

05:09.010 --> 05:11.440
It's case sensitive dot.

05:11.440 --> 05:14.950
So we have two ways of getting the data now decoded.

05:16.700 --> 05:21.170
Wrong data with, let's say, X.

05:21.410 --> 05:26.570
So we are going to print the decoded raw data with hexadecimal just like before.

05:27.050 --> 05:31.990
And we can also do sale dot print with i.

05:32.000 --> 05:32.540
R.

05:33.630 --> 05:35.970
Receiver Dot decoded.

05:37.700 --> 05:47.780
I r data dot com and this will actually give us a small number that is much easier to understand and

05:47.780 --> 05:48.890
much easier to control.

05:49.130 --> 05:55.790
So let's bring the two and I'm just going to add the print and then we've three dashes.

05:56.780 --> 05:57.130
Okay?

05:57.440 --> 06:03.380
So every time we read something, we can have three dashes to separate the results we get.

06:03.440 --> 06:07.280
And now let's run that code and let's upload it directly.

06:08.890 --> 06:10.610
And let's open the second monitor.

06:10.630 --> 06:12.410
And now we should not have any error.

06:12.430 --> 06:19.030
So I'm going to press any button and you can see when I press the button, I have an Exodus email result,

06:19.030 --> 06:23.140
which is also different from the one we had with version two.

06:23.620 --> 06:26.020
And we have second is a command.

06:26.320 --> 06:31.330
So if I press zero, I get this hexadecimal and the command 22.

06:31.360 --> 06:39.340
If I press one here, I get 12, I press two, I get 24, I press the let's say the on off button,

06:39.340 --> 06:45.310
I get 69, I press the play button, I get 64.

06:45.700 --> 06:47.620
So you get the hexadecimal value.

06:47.650 --> 06:53.530
If you have zero, it means that you have pressed the same button twice and then you also get a value

06:53.530 --> 06:58.210
that is actually easier to read and that is the value we are going to use.

06:58.210 --> 07:03.100
So from now on we are going to use the command that we get from the library.

07:03.250 --> 07:07.150
So as you can see, the version three of the library is an improved version.

07:07.150 --> 07:12.520
It's going to work better and we have a better data to handle.

07:13.030 --> 07:13.360
All right.

07:13.360 --> 07:15.880
And again, the code here, you don't need to really understand.

07:15.880 --> 07:21.580
Just know that you have to write this and then that you have to write this in order to get the information

07:21.580 --> 07:22.960
using the library.

07:24.380 --> 07:28.430
And now let's try to see what will happen if I try to put this code on.

07:28.940 --> 07:30.380
So I'm going to copy the code here.

07:30.410 --> 07:33.830
The code we have just used and put it on, think again.

07:34.190 --> 07:36.570
So now we are trying to use the version three.

07:36.590 --> 07:38.630
Let's start the simulation.

07:39.960 --> 07:41.580
And you can see we have some arrows.

07:41.580 --> 07:44.630
So what is the arrow in function void setup?

07:44.640 --> 07:48.810
I receiver was not declared in the scope so I r receiver.

07:48.810 --> 07:51.180
So here the line is not necessarily the correct one.

07:51.180 --> 07:55.890
This is that 1ir receiver is not known in the library.

07:56.010 --> 07:56.910
And why is that?

07:56.910 --> 08:00.570
Is because Tinker uses the version two of the library.

08:00.570 --> 08:05.750
So the I r receiver that is in version three is not known in version two.

08:05.760 --> 08:12.180
So if you use Tinker just here, this is the code for version two that's going to work.

08:12.180 --> 08:14.610
So if you use Tinker Cat, just use version two.

08:14.610 --> 08:19.500
And if you use your Arduino ID, well, I recommend you use version three.

08:19.500 --> 08:25.080
And for the following of this section, I'm going to keep using the version three of the library for

08:25.080 --> 08:29.700
the Arduino ID, but if you are following the course with Tinker Cat, well that's not really a problem

08:29.700 --> 08:33.810
because the code here, I'm not going to add anything else in that code.

08:34.050 --> 08:38.340
We are going to add code outside of the remote functionality.

08:38.340 --> 08:42.210
So this is all the code you need to get the sensor to work.

08:42.210 --> 08:48.540
So if you are using version two and I'm using version three, just modify the code for receiving the

08:48.540 --> 08:52.680
data with the remote controller and then everything else will be the same.
