WEBVTT

00:00.150 --> 00:06.920
This is the solution of the previous activity where you need to inform the user of the potential danger,

00:07.110 --> 00:14.480
OK, if the ultrasonic sensor detects an object that is too close from the robot or the area.

00:14.760 --> 00:20.910
So what I'm going to do first, I mean, it could be a. a crude and create new sketch that I'm going

00:20.910 --> 00:25.740
to name or copy paste and save as activity.

00:27.110 --> 00:27.770
15.

00:29.380 --> 00:37.330
So all the kahir is already set up to correctly get the distance from the ultrasonic sensor, and we

00:37.330 --> 00:41.340
don't block the execution of the application by using the Internet.

00:41.620 --> 00:42.730
So I know what I'm going to do.

00:42.730 --> 00:45.460
I'm going to first initialize the three entities.

00:45.980 --> 00:46.830
Let's go back here.

00:46.840 --> 00:47.850
Let's put that here.

00:48.550 --> 00:53.290
Define any one in which is 12.

00:55.750 --> 01:05.410
And the to the 11, so the other of the 10 is actually not that important as long as you just are consistent

01:05.440 --> 01:08.400
with how you use the valuable then in your program.

01:10.630 --> 01:17.600
And this so in the OK, we have to define here in the set up.

01:17.620 --> 01:22.930
I am going to do more in any one.

01:24.350 --> 01:24.710
In.

01:28.500 --> 01:40.380
And I'm going to do the same for the energy, too, and for the three entities are set up and now I'm

01:40.380 --> 01:40.800
going to.

01:40.830 --> 01:42.690
So I'm not going to write the code here.

01:42.690 --> 01:50.550
I'm going to do it nice with a new function that I'm going to put in void of to name dysfunction, let's

01:50.550 --> 01:51.390
say power.

01:53.060 --> 02:01.000
And it is from distance, OK, and this will get a perimeter double distance.

02:02.610 --> 02:07.940
So we are going to check for the distance we receive here in centimeter.

02:08.770 --> 02:12.180
I'm going to use a classic structure, OK, if dist..

02:14.040 --> 02:19.020
Is greater than one hundred and it's a greater or equal.

02:20.890 --> 02:22.930
OK, then, over on.

02:24.240 --> 02:24.600
Great.

02:25.750 --> 02:34.890
And if we use offensive, if the distance is greater or equal than, let's say, 15.

02:36.020 --> 02:38.420
And the distance.

02:39.870 --> 02:40.740
Is lower.

02:42.070 --> 02:43.090
Then 100.

02:45.580 --> 02:51.910
Then we Google glasses, but actually this we don't need to use it.

02:52.060 --> 02:59.460
OK, this condition is already through here because, well, if the distance is greater equal than 100,

02:59.470 --> 03:02.410
we go here and then if not, we go in.

03:02.590 --> 03:08.680
And if so, when we are in the cells, if we already know that the distance is strictly lower than one

03:08.680 --> 03:09.000
hundred.

03:09.280 --> 03:10.980
So we don't need to check that condition.

03:12.460 --> 03:20.380
So if the distance is greater than 100, great, if not so if the distance is lower than 100 but greater

03:20.380 --> 03:21.880
than 15, then.

03:23.100 --> 03:24.030
But we're on.

03:25.340 --> 03:25.920
Yellow.

03:27.200 --> 03:29.420
And then something else because.

03:30.740 --> 03:36.910
It means that the distance is strictly lower than 15, so we don't need to check the condition that

03:36.910 --> 03:37.490
we record.

03:37.510 --> 03:38.740
That is redundant.

03:39.040 --> 03:42.820
We just need to write the catch and put on.

03:43.480 --> 03:43.820
Right.

03:44.530 --> 03:45.840
So power hungry.

03:45.870 --> 03:48.640
We are going to do digital, right.

03:49.640 --> 03:57.590
And one in to know she's the right one, digital rights to.

03:58.730 --> 04:07.560
In two local also yellow digital rights, any three been high.

04:08.270 --> 04:13.440
This is the green one, I mean, to copy this and put it there.

04:14.090 --> 04:23.690
So now if the distance so if we are in the warning mode, we want to pull up on the yellow two.

04:24.440 --> 04:32.470
And if we are in the danger zone, we're having to pull up on any one but luck.

04:32.600 --> 04:36.320
So we have low, low, high, low, high, low and high, low, low.

04:37.310 --> 04:37.820
All right.

04:38.540 --> 04:42.560
So then what do we need to do is simply to call this function?

04:43.850 --> 04:46.280
Here, so we can print.

04:46.910 --> 04:54.440
Let's let's do that here so we get the distance and then we call power and it is from a distance we

04:54.470 --> 04:56.600
in the distance as a parameter here.

04:57.290 --> 05:00.920
And then we print also the distance to remove that.

05:02.300 --> 05:04.070
And well, that's pretty much it.

05:04.820 --> 05:11.390
So you see, we just have added one function, OK, and now the code in the void loop is almost the

05:11.390 --> 05:13.810
same and we didn't have to modify anything.

05:13.820 --> 05:20.070
It still works great, OK, because we have correctly used the time functionality here to trigger the

05:20.070 --> 05:23.210
retro sonic sensor and not block the code with delay.

05:23.540 --> 05:29.090
And because we have also used the pulse in function correctly so we don't block anything and now we

05:29.090 --> 05:31.520
have much more flexibility in the program.

05:31.790 --> 05:36.110
So now what are we going to do is to upload the.

05:36.140 --> 05:37.550
So let's verify first.

05:38.850 --> 05:41.250
And now let's upload the code.

05:42.300 --> 05:50.190
OK, let's open the cellular monitor and as you can see here, so we have OK, I'm going to move it.

05:51.930 --> 06:01.490
OK, we have one hundred forty centimeter and the green is spoiled, and now I'm going to put some obstacles,

06:01.500 --> 06:06.190
I'm going to put myself in the way, OK?

06:06.240 --> 06:14.060
And you can see here we are at 75 centimeters and you have the yellow there is on.

06:14.540 --> 06:15.510
You can see it.

06:15.510 --> 06:17.280
It's blinking a little bit.

06:17.400 --> 06:23.700
And it's because, well, you need to make sure that the scenario is quickly plug in the brain balled.

06:23.910 --> 06:28.700
It might move a little bit, so make sure it's correctly plugged.

06:29.430 --> 06:33.360
OK, that's one of the drawback of the breadboard is something you might have.

06:33.360 --> 06:43.090
Some components that are not like that will make the mixture directly, like in the rainbow.

06:43.560 --> 06:50.670
And now you can see if I put my hand very close from the sensor, you can see we have some going to

06:50.670 --> 06:51.600
put my two hands.

06:51.900 --> 06:55.250
You can see we have the right danger.

06:56.010 --> 06:57.830
The obstacle is ready to close.

06:58.080 --> 06:59.280
I'm going to go back.

07:00.090 --> 07:05.790
It goes to yellow and then I'm going to remove every obstacle and now it goes to green.

07:08.840 --> 07:14.420
All right, it's working, so now you have a visual indication to know if the obstacle is too close

07:14.420 --> 07:15.260
from the sensor.
