WEBVTT

00:00.180 --> 00:07.310
This is the number six of the final project, so now that we have initialized the liquid crystal, also

00:07.320 --> 00:15.350
the LCD screen, we are going to use it to print the correct distance measured by the ultrasonic sensor.

00:15.600 --> 00:22.440
So we already have some visual information with the yellow OLED, which is blinking faster if the obstacle

00:22.440 --> 00:23.130
is closer.

00:23.610 --> 00:25.350
And then we have the locked mode.

00:25.770 --> 00:31.800
Whenever the obstacle is getting to close with the LCD, we are going to be able to get more information

00:32.040 --> 00:35.670
and also to be able to give the user some instructions.

00:35.670 --> 00:42.290
For example, when the application is not to say that you have to press the button to unlock the application.

00:42.570 --> 00:43.670
So let's do this.

00:44.490 --> 00:50.070
So I'm going to create a new function that's created here.

00:50.790 --> 00:56.040
Void print distance on NCG.

00:58.040 --> 01:01.320
And we get the distance in centimeters.

01:01.360 --> 01:04.290
OK, again, I'm using centimeters here.

01:04.520 --> 01:07.510
We are going to convert to inches later in the project.

01:07.820 --> 01:14.030
And so here what I want to do, I want to check first if he's locked.

01:15.680 --> 01:25.190
OK, and then it's so I'm going to use a different behavior if the application is locked out, the application

01:25.190 --> 01:30.680
is not locked, OK, if it's locked, I'm going to bring some error message until the application is

01:30.680 --> 01:32.930
unlocked and with some instruction.

01:33.110 --> 01:38.960
And if it's not locked, I'm going to put simply the distance and maybe with a warning we can other

01:38.960 --> 01:46.760
one, OK, we can add an intermediate threshold, for example, 50 centimeters to say that if the obstacle

01:46.760 --> 01:54.950
is at a distance lower and 50 centimeters, we print a warning, OK, before we get to the error state.

01:55.460 --> 02:00.770
So one thing I'm going to do is call that function whenever we get the distance here.

02:01.670 --> 02:02.360
Look here.

02:04.460 --> 02:07.600
So this we continue to read it, OK?

02:07.610 --> 02:13.610
We continue to rule whatever happens, we continue to rate the distance and then they print the distance

02:13.880 --> 02:19.320
the and depending on the is locked, which is already set.

02:19.340 --> 02:23.690
OK, with the lock and unlock function, we already have the mechanism which is working now.

02:23.690 --> 02:29.170
We just need to use that, like to know if the application is locked out.

02:29.510 --> 02:34.550
So let's start with the normal behavior if the application is not locked.

02:34.550 --> 02:35.670
So normal behavior.

02:36.080 --> 02:40.280
What I'm going to do is print on the first line distance and print on the second line.

02:40.280 --> 02:42.350
Some information research.

02:42.710 --> 02:44.750
OK, so acidy set.

02:45.920 --> 02:52.820
Just so I'm going to use the Kyozo with zero and zero to be on the first column, first line.

02:54.080 --> 03:01.010
And in the end, Saudi brains, I'm going to do this, not distance, because we have distance, we

03:01.010 --> 03:05.390
will not have the place to print the distance and the unit.

03:05.960 --> 03:09.830
So just this and the intensity that Prince.

03:11.880 --> 03:19.160
Distance or the distance that we get here in the parameter and function and then acidy, that brains

03:19.170 --> 03:23.720
are going to bring to the unit, which is fono centimeters, we're going to come back to that later

03:23.970 --> 03:31.200
and I'm going to adjust a few spaces, OK, just in case, because the distance here, if we have three

03:31.560 --> 03:38.040
digits or for example, the distance is one hundred forty point zero zero, then we have one, two,

03:38.070 --> 03:40.290
three, four, five, six characters.

03:40.620 --> 03:43.520
But now let's say it's 14 centimeters.

03:43.540 --> 03:43.920
We have.

03:44.950 --> 03:50.870
Only five characters, OK, if it's eight centimeters, we have only four characters.

03:51.520 --> 03:58.660
So with the additional spaces, we make sure that if the new text we print is smaller than the previous

03:58.660 --> 04:02.080
one, we don't keep the previous characters at the end of the line.

04:02.110 --> 04:05.040
OK, so the first line, we bring the distance.

04:05.260 --> 04:05.760
All right.

04:06.010 --> 04:08.410
And then I'm going to LCD set.

04:10.310 --> 04:20.750
Just so we've zero and one to start in the segment and then check, if so, what are you going to do

04:20.750 --> 04:24.860
is I'm going to add a new here we have long distance.

04:25.210 --> 04:27.440
I'm going to say define.

04:29.570 --> 04:37.310
Running distance, which is 50 centimeters, and again, those values, you can just modify them as

04:37.310 --> 04:37.630
you want.

04:37.820 --> 04:44.720
You just need to modify your view here and it will automatically update all your program with this new

04:44.720 --> 04:45.120
value.

04:45.140 --> 04:48.430
So that's very convenient, as you can see, to use to define you.

04:49.340 --> 04:50.570
So one in distance.

04:52.240 --> 04:59.680
I'm going to put that here if the distance so we get the distance in the distance is greater than the

04:59.680 --> 05:00.670
warning distance.

05:01.910 --> 05:03.950
Let's say got print.

05:05.360 --> 05:08.660
No obstacle, OK?

05:08.810 --> 05:18.260
Nothing to report and let's have a few spaces here to reach 16 or more characters and then else, which

05:18.260 --> 05:25.430
means that the distance is lower than the one in distance or the distance here will be lower than 50

05:25.670 --> 05:26.470
centimeters.

05:26.870 --> 05:29.090
And we do Elsley print.

05:30.330 --> 05:33.600
We let's say two exclamation mark in one.

05:35.870 --> 05:37.570
And it's quite a few species here.

05:39.590 --> 05:45.620
And then we don't need to check for the case when the distance is lower than the log threshold, because

05:45.620 --> 05:51.890
if this is the case, we are going to look we're going to log the application here.

05:52.160 --> 05:59.000
And because we love the application, we are going to enter the if is logged on the print distance and

05:59.000 --> 05:59.760
kidney function.

06:00.200 --> 06:06.860
So with the logic, we have said here, we are never going to enter this block of code if the application

06:06.860 --> 06:07.280
is blocked.

06:07.670 --> 06:12.090
So we don't need to check for the log threshold here, just the warning threshold.

06:12.560 --> 06:22.370
OK, so we have the normal behavior first distance in the distance in centimeters and then the message,

06:22.420 --> 06:24.770
no, a warning message.

06:24.950 --> 06:30.050
If we start to get close to the obstacle and then if the application is blocked, what are you going

06:30.050 --> 06:30.460
to do?

06:30.470 --> 06:36.890
So LCD set just saw zero zero to start the first line, first column.

06:37.610 --> 06:43.460
So now every time you call the brain first, you need to set the Kyosuke because you don't necessarily

06:43.460 --> 06:47.900
know where the Kyozo was set the last time you printed something.

06:47.900 --> 06:49.090
OK, it can be anywhere.

06:50.240 --> 06:52.310
And then I'm going to acidy prince.

06:54.310 --> 07:02.230
With three exclamation mark obstacle, and it's the other three and some species.

07:03.400 --> 07:06.970
And LCD does print, so said.

07:08.310 --> 07:09.240
Kyozo, actually.

07:11.070 --> 07:20.190
We zero one and see print, that's the price to unlock a few spaces.

07:21.270 --> 07:29.310
So here we print a big error message, ending price to unlock, to give an indication to the user of

07:29.310 --> 07:31.250
what to do to download the application.

07:31.500 --> 07:36.710
And the thing is that the lock mechanism, we don't need to do anything else.

07:36.930 --> 07:41.670
We just need to add action if it's locked at in action, if it's not locked.

07:41.730 --> 07:45.770
OK, because the lock mechanism is already handled here in the vault.

07:45.800 --> 07:50.910
Look like it's already handled with the lock here and with the lock you.

07:52.710 --> 07:59.460
So now, depending on each state of the application, we just need to say, OK, if this is that state

07:59.460 --> 08:02.700
we do this, if it is that other state, we do that.

08:03.090 --> 08:04.200
And that's quite simple.

08:04.500 --> 08:12.840
So once you have a solid foundation for your program, you can easily add new blocks that add nice functionalities

08:13.500 --> 08:18.540
without having to rewrite the entire mechanism, just using what you have built previously.

08:19.170 --> 08:20.990
OK, I think this is complete.

08:21.000 --> 08:25.570
So let's say let's verify and let's save some final project.

08:25.570 --> 08:28.440
Step number six, save it.

08:30.820 --> 08:33.990
Let's upload the code to the original.

08:37.060 --> 08:42.820
So you will see initializing and then you see first the distance on the first line here, one hundred

08:42.820 --> 08:46.040
forty centimeters and then no obstacle.

08:46.240 --> 08:49.080
So what I'm going to do is first I'm going to.

08:49.150 --> 08:52.350
So I'm need to add something in front of the sensor.

08:52.360 --> 08:56.760
But let's see here at about 30 centimeters, 25.

08:57.130 --> 08:58.400
And you can see one.

08:58.720 --> 08:59.990
So we start to have a warning.

09:00.020 --> 09:03.590
So the here and the yellow and it is blinking faster.

09:03.650 --> 09:09.420
Now we have the warning and the closer I get, I can see now we have the distance.

09:09.430 --> 09:13.540
And when I reach 10 centimeters, now you can see.

09:13.570 --> 09:19.960
So the application is locked and you can see no obstacle press to unlock and can see whatever I do.

09:19.960 --> 09:22.300
If I remove any obstacle, it's still not.

09:22.300 --> 09:23.510
So nothing will change.

09:23.890 --> 09:28.400
Now I need to press on the push button and it goes back to normal.

09:28.810 --> 09:33.880
OK, once again I go closer, closer and the application is locked.

09:35.450 --> 09:40.750
So as you can see, adding an LCD screen to your project is really nice because you can print anything,

09:40.750 --> 09:45.980
you can bring some data you get from the program, you can print some instructions, some warning,

09:45.980 --> 09:51.760
etc. This will give really useful instructions to the user of your application.

09:51.770 --> 09:56.170
And because you use the LCD screen, as you can see, we don't need to use the same monitor anymore.

09:56.180 --> 10:01.940
So from now you could power on your Arduino from any USB power source.

10:02.360 --> 10:10.280
Just put it on the program and just follow along with the instructions and values you see on the LCD

10:10.280 --> 10:10.630
screen.

10:11.030 --> 10:12.710
And that is the end of this step.
