WEBVTT

00:00.270 --> 00:07.560
This is now step number four of the final project in the state, we are going to unlock the applications.

00:07.560 --> 00:14.500
So far what we have done is read the distance from the ultrasonic sensor, both on the warning and the

00:14.550 --> 00:19.650
faster is the obstacle is closer and then lock the application.

00:19.650 --> 00:25.980
If the distance is lower than the certain threshold here, 10 centimeters in that case, we of the right

00:25.980 --> 00:28.710
in the default behavior and we make the IDs.

00:28.980 --> 00:35.610
So the one and the error and it is blinking and not with the things that once the application is locked,

00:36.180 --> 00:37.590
we can't do anything else.

00:37.830 --> 00:45.090
So we know what we need to do is create a mechanism to unlock the application when a user, for example,

00:45.300 --> 00:48.310
a human user, presses on a push button.

00:48.900 --> 00:52.080
So in real life, that could be that you're about to stoke somewhere.

00:52.080 --> 00:55.230
The user would make sure the robot is not stacked anymore.

00:55.470 --> 00:59.160
And we press on a button to say that now everything is OK.

00:59.160 --> 01:01.650
You can resume your normal behavior.

01:01.920 --> 01:08.010
So let's handle the push button, because this is when we press on the button that we are going to unlock

01:08.370 --> 01:09.050
the application.

01:09.060 --> 01:10.800
So I need for Dippin.

01:12.940 --> 01:21.070
The fine button in which he's been number two, and he will for the president and we are going to need

01:21.070 --> 01:26.140
to debate the button, which we're going to do in the code, and we can choose between using polling

01:26.140 --> 01:27.340
or interrupts.

01:27.790 --> 01:31.740
And actually, I'm not going to interrupt in that final project for a button.

01:32.050 --> 01:34.780
I'm going to interrupt for the address and make OK.

01:34.820 --> 01:37.970
This is already perfect for this budget, for the budget.

01:38.080 --> 01:42.880
And I'm going to use Pawling and check the burden states only when the application is blocked.

01:43.180 --> 01:49.000
So the thing is that in that case, using polling will not be a problem because we will never be stuck

01:49.180 --> 01:50.880
somewhere in the void loop.

01:51.100 --> 01:54.040
So we are not going to miss the data from the button.

01:54.340 --> 01:56.330
So I have my button pinned here.

01:56.350 --> 02:06.360
I'm going to say I have made available for ultrasonics one error and I'm going to add button here as

02:06.460 --> 02:06.910
button.

02:09.040 --> 02:13.420
And the unsigned long last time.

02:14.920 --> 02:24.250
But then changed, so this will not be used to trigger the button and do something every X amount of

02:24.250 --> 02:24.580
time.

02:24.610 --> 02:26.590
This is just for the debates.

02:26.710 --> 02:34.270
OK, we check when the last time the button has changed so we can make sure that when the button changes,

02:34.780 --> 02:41.800
we ignore the following few changes for a few milliseconds so we don't count all the physical bounces

02:42.190 --> 02:44.350
that happen on the physical button.

02:46.150 --> 02:51.670
Unsigned, long, but demands delay, which is.

02:52.710 --> 02:59.880
Let's put 50 milliseconds and bytes by the state we need to monitor the states.

03:00.260 --> 03:02.620
Actually, I'm not going to initiate it here.

03:03.720 --> 03:10.430
Now, I am going to go in the void setup and I'm going to do clean mode.

03:11.980 --> 03:19.030
Button being input and just after that, so button state.

03:20.210 --> 03:24.620
Is equal to Digital three Budden.

03:25.460 --> 03:32.570
So instead of initializing the state to an arbitrary state, let's just read the real state for the

03:32.570 --> 03:32.940
bottom.

03:33.010 --> 03:36.640
OK, and then so Lebanon is set up.

03:36.650 --> 03:40.500
We have all the variables we need in the void loop.

03:40.520 --> 03:49.010
What I'm going to do is so if is locked, we make the edit is being and I'm going to do so at the same

03:49.010 --> 03:49.370
time.

03:49.910 --> 03:53.030
I'm going to check for the push button here.

03:53.660 --> 03:59.360
So when the application is not locked, well, we don't check for the pushbutton because the pushbutton

03:59.360 --> 04:01.460
is only here to unlock the application.

04:01.460 --> 04:04.360
So no need to check for it any time.

04:04.790 --> 04:08.810
We're just going to check the state when the application is looked.

04:09.350 --> 04:12.470
So to read the state, which is digital, read for the button.

04:12.470 --> 04:15.860
But I'm also going to write the DBMS mechanism.

04:16.040 --> 04:26.810
So time now if time minus last time button changed, if this is greater than the button demands delay,

04:27.680 --> 04:30.290
then what we're going to do is do so.

04:30.560 --> 04:32.720
New button state.

04:34.410 --> 04:36.630
Is equal to digital.

04:38.380 --> 04:41.130
We with the.

04:42.870 --> 04:50.430
So if the state doesn't change, we continue to read it at full speed and now if the Golden State is

04:50.430 --> 04:50.880
different.

04:52.330 --> 04:58.870
Like the new Golden State is different from the bottom state, we have stalled what we are going to

04:58.870 --> 05:02.800
do is last time.

05:06.530 --> 05:20.600
Change is equal to time now and button that is equal to a mute button state and then do the action we

05:20.600 --> 05:20.790
want.

05:21.740 --> 05:24.460
So this again, things you don't understand this structure.

05:24.470 --> 05:27.530
Please go back to the demands section.

05:28.040 --> 05:34.490
And now we are going to unlock the application so the button we can press on the button and we can release

05:34.610 --> 05:35.020
the button.

05:35.030 --> 05:41.060
So I actually am going to check if Button State is low.

05:41.060 --> 05:46.020
So here I decide to do the action when we release the book.

05:46.730 --> 05:57.440
OK, and because I have created a lock function, I'm going to create analog function and let's so we

05:57.440 --> 06:00.110
have largely to avoid a ADNOC.

06:01.710 --> 06:09.150
And let's right the mechanism to unlock the application, so here, when I looked a first check, if

06:09.150 --> 06:10.330
it was not locked.

06:10.350 --> 06:12.110
OK, so I'm going to do the same here.

06:12.120 --> 06:18.990
I'm going to do but the opposite, actually, if it is blocked, then I can unlock it.

06:19.180 --> 06:26.700
OK, so I just had this small condition to make sure that we don't unlock the application when it's

06:26.700 --> 06:27.870
already unlocked.

06:28.320 --> 06:32.460
And then I'm going to do is locked is false.

06:32.940 --> 06:35.880
And note that I have set the flag to false.

06:36.600 --> 06:39.630
The thing is that the volume will continue to grow.

06:39.690 --> 06:40.120
OK.

06:40.410 --> 06:49.610
And now instead of going inside this, if he's locked, we are going to go with the X, so the red energy

06:49.680 --> 06:51.940
will not blink anymore.

06:52.140 --> 06:54.630
We are not going to take the button state anymore.

06:55.170 --> 07:01.470
Instead, we are going to go back to normal behavior and make the yellow and blink with the blink rate

07:01.470 --> 07:02.870
depending on the distance.

07:02.880 --> 07:05.840
And we also continue to read the distance.

07:06.570 --> 07:12.300
So now that the application is unlocked, we read the distance and again we check if the distance is

07:12.300 --> 07:15.210
lower than the long distance, then we lock the application begin.

07:15.930 --> 07:21.380
So now we would be able to lock the application and lock the application, lock the application, etc..

07:21.960 --> 07:30.660
And one thing here is that in the end, look, what I'm going to do is also do hero.

07:31.080 --> 07:45.660
Editing state to low and digital rights are a 15 year old data states and also apply the state to the

07:46.110 --> 07:55.200
area at Dippin simply because here, if we stop targeting the right any means that maybe we are going

07:55.200 --> 08:01.410
to stop when the boiled off, but maybe we are going to stop when the ADHD bobbled on.

08:01.770 --> 08:08.220
So what may happen when you unlock the application is that the right ending will be put on and you don't

08:08.220 --> 08:08.550
want that.

08:08.550 --> 08:10.470
You want it to be pulled off.

08:10.470 --> 08:14.160
So we make sure it's of when we unlock the application.

08:15.170 --> 08:19.580
Actually, here there is a saying we to comment because we don't need that anymore.

08:21.050 --> 08:26.780
Now, if you want to test, I'm going to test with the real secret and we are going to see if it's working

08:26.780 --> 08:29.240
simply with the behavior of the it is.

08:29.540 --> 08:38.840
But what you could also do is here I'm just going to say a little print and I'm looking, for example,

08:39.260 --> 08:40.250
and do.

08:42.090 --> 08:43.050
You and.

08:45.620 --> 08:52.460
Looking OK, so you can also when you get to that function here, when you get to that function here

08:52.820 --> 08:58.100
with the cell monitor, so you make sure you don't enter this function when you don't need to.

08:58.610 --> 09:01.910
So that's an additional week to bring your program if you need to.

09:02.420 --> 09:02.830
All right.

09:03.140 --> 09:07.360
To recap quickly here and bring us to their final call.

09:07.530 --> 09:10.820
OK, so final project, step number four.

09:12.820 --> 09:14.630
Let's see if it complies, yes.

09:14.650 --> 09:18.250
So to recap quickly on the code I have, so initialize the button.

09:18.260 --> 09:25.600
Thien initialized some variable for the deboned functionality of the button and then so we keep those

09:25.600 --> 09:26.290
functions.

09:27.450 --> 09:34.860
I have created the unlooked function, which shak so if it's already locked, we unlock the application

09:35.220 --> 09:42.000
and we pull out of the editing by setting the building in the setup and in the loop, I check the button

09:42.000 --> 09:42.350
state.

09:42.360 --> 09:51.600
And basically when the button is worthy's here, let's seek release when the button is released and

09:51.600 --> 09:55.710
also when the state is locked, then we call the analog function.

09:56.070 --> 10:02.300
Now we have a mechanism to lock and unlock the application and now let's blow the code to the original.

10:04.570 --> 10:13.510
So I still have my yellow calendar, which is blinking, and if I go closer here, the lady will blink

10:13.510 --> 10:20.860
faster and here I have reached the point where so the 10 centimeters where the application will be looked,

10:21.160 --> 10:23.710
you can see now the two entities are blinking together.

10:24.010 --> 10:26.400
And now I have a way to unlock the application.

10:26.410 --> 10:32.770
I'm going to press on the button and you can see it's going back to not not if I look again.

10:35.630 --> 10:36.140
OK.

10:37.560 --> 10:43.200
And I can unlock it and is going back to normal so I can alternate between the two states.

10:44.360 --> 10:50.150
All right, so now you have already completed the main functionality of this project, which is to lock

10:50.300 --> 10:54.470
and unlock the application depending on the measured distance.

10:54.830 --> 11:00.170
Now, what we are going to do in the next few steps is to improve all the other functionality around

11:00.170 --> 11:07.270
that main functionality to make the project nicer with more information that we can get and with more

11:07.280 --> 11:08.330
interactiveness.
