WEBVTT

00:00.210 --> 00:07.770
And now let's write the code to know what was the button that was pressed on the infrared remote control.

00:08.430 --> 00:14.420
So here we are going to use the remote library that we have just installed before and you will see.

00:14.450 --> 00:16.590
So we're going to use digital PIN number five.

00:16.780 --> 00:26.000
The first one I'm going to do is define that's name AIPA and then receive in OK.

00:26.070 --> 00:28.170
And this is digital PIN number five.

00:28.180 --> 00:34.820
So make sure you use the correct pin if you have changed the pin to another one of these accordingly

00:34.890 --> 00:38.790
and know when we are not going to directly use this with digital red digital.

00:38.790 --> 00:39.210
Right.

00:39.630 --> 00:42.680
Whatever we're going to use directly the library.

00:42.690 --> 00:45.950
OK, which will handle the pin for us and to use the library.

00:45.960 --> 00:51.930
Well, I'm going to write some instructions and there is nothing or I need to understand here is just

00:52.260 --> 00:53.500
how to write the instructions.

00:53.520 --> 00:57.390
So this is just some syntax you have to write so you can use the library.

00:57.720 --> 01:06.760
OK, so I'm going first to do I receive like this so I r and R e c the lowercase.

01:07.240 --> 01:08.590
OK, so this is the type.

01:08.850 --> 01:14.640
This is the data type that is defined here in the library to create the object available that we can

01:14.640 --> 01:17.970
use to receive and process the signal.

01:18.280 --> 01:19.360
And I'm going to name it.

01:21.300 --> 01:28.980
So the same but all lowercase, OK, and here I need to give one parameter frontages, which is the

01:28.980 --> 01:33.080
number of the people like this with semicolon.

01:33.780 --> 01:43.010
And then I need to also decode and here with an underscore results like this, you can see terms around

01:43.020 --> 01:43.830
and let's go.

01:43.830 --> 01:46.980
That does nothing really to understand.

01:47.010 --> 01:48.590
That's just how you have to write.

01:48.930 --> 01:51.750
OK, in the setup, what I'm going to do in the set.

01:51.870 --> 01:57.360
So I'm going first to initialize cellular communication because we are going to print the results on

01:57.360 --> 01:57.820
the same.

01:57.840 --> 01:58.200
So.

02:00.140 --> 02:10.790
That's initial sale, and then I need to use the receiver that I've created here, I received that enabled

02:11.300 --> 02:18.720
I up in Ladies the I uppercase and then the eyes of a kitten in lowercase.

02:19.490 --> 02:22.730
This will enable the with the library.

02:22.880 --> 02:28.340
Again, why I use this because I have told you that it's better to use a meaningful name and this is

02:28.340 --> 02:34.670
actually not a real meaningful name is just because well this is actually the typical example you can

02:34.670 --> 02:35.660
find on the Internet.

02:35.660 --> 02:42.170
So if you need to actually get more examples or get more help from the Internet, it's also sometimes

02:42.170 --> 02:45.200
better to use the convention that everyone is using.

02:45.200 --> 02:46.610
So everyone is using that.

02:46.880 --> 02:49.730
I'm going to use that as well for this library.

02:50.090 --> 02:58.270
And individual books are not the same and so is initialized with the three lines here in the loop.

02:58.280 --> 03:10.820
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

03:11.690 --> 03:12.230
results.

03:14.690 --> 03:17.460
So this is a complaisant out of the scope of this schools.

03:17.480 --> 03:21.350
But basically I give the reference to the results structure here.

03:21.710 --> 03:24.350
You just need to know that you have to write this code like this.

03:24.680 --> 03:29.970
And this is really similar to when we did, for example, if the label.

03:29.990 --> 03:37.670
OK, this will just tell you if there are some results, if you can decode some results from DICENZO

03:37.880 --> 03:41.660
and it will put the result inside the results variable that we have here.

03:42.080 --> 03:47.450
So then what you can do is so let's do some that print and then get the results.

03:47.450 --> 03:55.280
You can do results that value, OK, and this time No Ambersons and we do this.

03:55.520 --> 03:59.390
And one thing that is important is after you have used decode.

03:59.390 --> 04:03.770
So if you can do that here or after the sale, the printer doesn't matter.

04:04.130 --> 04:05.270
You have to do so.

04:05.630 --> 04:06.380
Do this again.

04:06.380 --> 04:08.710
I'll receive that regime.

04:09.680 --> 04:15.590
OK, whenever you decode the results, you have to resume after that so you can will continue for the

04:15.590 --> 04:16.490
next rate.

04:16.880 --> 04:19.420
And let's run that program.

04:19.430 --> 04:20.930
OK, let's upload.

04:23.200 --> 04:30.910
And don't go blowing, so I'm going to open the sale monitor, OK, which should not contain anything

04:30.910 --> 04:35.940
now and I'm going to take the remote control over here and I'm just going to press on no.

04:35.990 --> 04:37.360
So let's say No.

04:37.360 --> 04:37.790
One.

04:38.430 --> 04:41.420
OK, and you can see here we have the red ality.

04:41.920 --> 04:48.370
That is whenever I send some data, whenever I press a button, you can see on my sensor I have the

04:48.610 --> 04:51.580
ability to just tell that I have received something.

04:51.580 --> 04:57.070
So maybe you will have that or not in your secret and you can see in the monitor.

04:57.400 --> 04:59.320
So let's say press one again.

05:00.820 --> 05:04.720
I have some number, rather big number.

05:04.930 --> 05:11.500
If I keep pressing, I have a different number and I press to press one, two, three.

05:11.500 --> 05:15.830
For example, I press the button plus the volume minus.

05:15.880 --> 05:21.890
OK, you can see for each different button I have different values.

05:21.950 --> 05:22.270
OK.

05:23.280 --> 05:29.430
So if you have the results like this, this means that it's working for you and you also may not have

05:29.430 --> 05:31.350
the same values as me, OK?

05:31.530 --> 05:33.650
Each controller will send different numbers.

05:33.660 --> 05:35.310
I'm going to explain that later.

05:35.850 --> 05:38.600
So here we have some big numbers.

05:38.610 --> 05:45.840
What I'm going to do, instead of just printing the results like that, I'm going to add X like this

05:45.840 --> 05:48.490
in uppercase and this should turn blue.

05:49.230 --> 05:49.810
What is that?

05:49.860 --> 05:56.490
Basically, we sell the print and then I'm going to be able to print either the number like this, print

05:56.490 --> 05:58.590
the number in hexadecimal.

05:59.100 --> 06:01.040
So hexadecimal to make it simpler.

06:01.050 --> 06:03.300
It's just another way to represent the number.

06:03.540 --> 06:06.960
OK, so basically you have different ways of representing number.

06:06.970 --> 06:13.820
For example, binary binary is just zero or one in the decimal system that we all know.

06:14.040 --> 06:17.730
We have numbers from zero to nine in the habit of this.

06:18.030 --> 06:26.970
Well, the number goes from zero to nine and then you have A, B, C, D, E, and so you have 16 numbers

06:27.240 --> 06:30.480
and ABCDE and F our numbers after nine.

06:30.510 --> 06:37.320
OK, so basically you will have that number or representation with stuff between zero and nine and eight

06:37.320 --> 06:37.860
to F.

06:38.340 --> 06:41.240
So let's upload the code again.

06:42.550 --> 06:47.380
And this is actually will be more readable and let's say a monitor.

06:47.450 --> 06:53.290
OK, I'm going to press zero again and I have the exact decimal number here.

06:53.470 --> 06:58.820
OK, we've f f and you can see eye to eye by three, I press nine.

06:59.050 --> 07:02.500
We have different numbers here in hexadecimal.

07:02.860 --> 07:10.870
OK, I can press any button like to play button to go first button fastforward first Buckwald etc..

07:11.140 --> 07:16.120
And if I keep pressing on the button, let's say keep pressing on any button you can see then I have

07:16.390 --> 07:17.650
a lot of F's.

07:18.020 --> 07:24.880
OK, so whenever you press the button, once you have one hit number, whenever you keep pressing on

07:24.880 --> 07:27.880
the button, you have F F F.

07:28.030 --> 07:35.110
So it means that you have pressed on the same button as before continuously and be careful because the

07:35.500 --> 07:37.470
remote controller can be quite sensitive.

07:37.660 --> 07:40.020
So sometimes you will press on the button twice.

07:40.030 --> 07:44.290
OK, and again, this is because this is probably not the best quality ever.

07:44.770 --> 07:46.840
So make sure that you just press once on the.

07:48.560 --> 07:55.340
Once quick and sometimes when you press the button, so if I press too, I know that, OK, press to

07:55.340 --> 08:03.560
multiple times, I know that this is the number four to OK and sometimes so it's not happening here.

08:03.560 --> 08:11.000
But for other numbers, you may have some garbage data other than these are fair, but that's not a

08:11.000 --> 08:14.870
problem because later on we are going to be able to tell exactly when we have this.

08:15.140 --> 08:18.650
This is number two, for example, or when we have this.

08:20.060 --> 08:25.400
OK, you can see I have some weird data here, for example, this is weird, but when we have this,

08:25.400 --> 08:26.890
we know it's the play button.

08:26.900 --> 08:29.510
So if we have this, we are going to ignore that value.

08:30.110 --> 08:30.560
All right.

08:30.560 --> 08:36.770
So now you are able to decode the signal you got from the infrared sensor with this code and you can

08:36.770 --> 08:39.780
get each different button that you press.

08:39.890 --> 08:41.800
You will get a different value here.

08:42.140 --> 08:45.890
So each button of your remote controller will give you a different value.

08:46.070 --> 08:49.360
And also each different controller may give you different values.

08:49.360 --> 08:55.820
So the controller you have will probably give different values that the controller I have him again

08:55.820 --> 08:59.870
here is the same code that I've written for Tinker.

09:00.150 --> 09:03.560
So let's upload the code and you can see it should work.

09:05.060 --> 09:11.270
Using the two point six, put one of that library, OK, this is the thing called the long link to open

09:11.270 --> 09:17.850
the same monitor here and I'm going to press on the button, say zero to any button I can press.

09:17.900 --> 09:22.160
OK, you can see we give us a different number in Hexa.

09:22.190 --> 09:27.050
This if I keep pressing, you can see I have the f f f f f.

09:27.350 --> 09:27.710
All right.

09:27.720 --> 09:30.860
So it's the same thing as using the real controller.

09:31.190 --> 09:31.660
But here.

09:31.670 --> 09:33.080
No, this is important.

09:33.470 --> 09:34.130
Let's see here.

09:34.130 --> 09:37.730
I still have this monitor on my real secret.

09:37.880 --> 09:39.500
I'm going to press number zero.

09:40.830 --> 09:52.990
So number zero, I have F F 68, 97, the zero and have F the 30 S.F. So that's a different number.

09:53.030 --> 09:55.380
OK, that's the exact same controller.

09:55.410 --> 09:59.320
OK, this looks like the exact same controller, but we have different values.

09:59.360 --> 10:02.680
OK, because as I told you, each controller.

10:02.790 --> 10:04.930
OK, even the same ones.

10:04.980 --> 10:10.120
OK, in the same kids, each controller, different hardware can give you different values.

10:10.140 --> 10:15.090
So you are going to need to map the values depending on the controller you are actually using.

10:15.480 --> 10:15.810
All right.

10:15.820 --> 10:20.880
So that is how it works with the version two of the remote library.
