WEBVTT

00:00.120 --> 00:06.390
This is the solution of the previous activity where you need to bring the distance of the ultrasonics

00:06.390 --> 00:11.790
and Suso the distance measured by the sensor in the LCD display screen.

00:12.270 --> 00:13.440
So what are you going to do?

00:13.470 --> 00:15.530
I'm not going to start from scratch here.

00:15.570 --> 00:17.910
I recommend you to do it so you can practice more.

00:18.270 --> 00:23.880
I'm going to take the code for the ultrasonics, and so I'm going to take the code for the LCD screen

00:23.880 --> 00:25.850
and then add the functionality.

00:26.190 --> 00:31.000
So I'm going to open the activity, will hear the activity.

00:31.030 --> 00:34.400
15 in this activity.

00:34.980 --> 00:40.490
We were using the ultrasonic sensor with some LCD.

00:40.560 --> 00:44.510
OK, we are not going to use HD here, so I'm just going to take what I need here.

00:44.970 --> 00:52.840
So I have to define for the eco and the trigger pins and have all of that that I'm going to use.

00:53.300 --> 00:59.370
OK, so to set the time for the trigger, to set time for the pulse in the distance, the previous distance

00:59.370 --> 01:02.040
for the filter that we use.

01:04.230 --> 01:12.510
And then to trigger ultrasonics and so is the same function, I just think these douget, ultrasonic

01:12.660 --> 01:15.940
dist., is also the same.

01:16.680 --> 01:16.960
OK.

01:18.130 --> 01:27.220
They go down, then we have the echo interrupt, which is the same I don't mean this poor elitist from

01:27.230 --> 01:31.200
distance because we are not going to use them in an indoor setup.

01:31.210 --> 01:35.020
So in the setup, I have my Selvig in.

01:37.160 --> 01:41.060
I have the PIN code for echo and trigger pins.

01:43.000 --> 01:47.380
I don't need to mode for the ads, and I need also this interrupt.

01:51.750 --> 01:53.160
That's Bunnett here.

01:55.610 --> 02:01.400
And then in the void loop, where what do I do, I am just going to take everything.

02:03.360 --> 02:11.790
OK, and just remove this, we don't need to pull this from a distance, so that is the code to actually

02:11.790 --> 02:17.130
trigger the ultrasonic sensor every 16 milliseconds.

02:17.550 --> 02:23.700
And then we have to interrupt to handle the measurement of the distance and then we get the distance

02:23.700 --> 02:26.160
in our code directly in here.

02:26.160 --> 02:28.740
We just print it on the same monitor.

02:28.920 --> 02:35.210
Actually, I'm going to run most of sales because we are not going to use cell in this activity.

02:36.250 --> 02:42.220
But it can be good for you to use it when you're actually writing this program to test the program and

02:42.220 --> 02:44.810
see if things are working correctly here.

02:44.860 --> 02:48.730
I suppose that it's going to work because it was working for this activity.

02:49.600 --> 02:52.690
So I think I got everything I need.

02:52.840 --> 02:57.370
Just verify the sketch work activity.

02:58.950 --> 02:59.770
17.

03:02.070 --> 03:04.400
Let's see if we have an error, good.

03:04.570 --> 03:06.780
I'm going to open the activity.

03:08.040 --> 03:08.610
16.

03:09.950 --> 03:19.160
In which we have used the LCD screen and I'm going to initialize it here, so I'm going to include the

03:19.160 --> 03:19.860
library.

03:22.010 --> 03:26.250
And I'm going to do the defiance of the other for the defying doesn't matter.

03:27.170 --> 03:32.430
OK, then NCDC going to also take the course online here.

03:33.170 --> 03:34.710
So let's put that here.

03:34.730 --> 03:37.570
OK, the other here doesn't really matter.

03:37.970 --> 03:43.880
You have all your designs and then all the initialization of your global variables.

03:45.360 --> 03:51.910
And then we have the different functions, and so we don't need to use a text on display.

03:51.990 --> 03:58.350
OK, why do we need to do now is to set up the LCD we LCD Biggin.

03:59.770 --> 04:03.870
And I'm going to do that just here in the city.

04:04.150 --> 04:06.080
And that's pretty much.

04:08.100 --> 04:15.780
So now we have the reading of the ultrasonics, and so every 60 milliseconds, every whatever we put

04:15.780 --> 04:20.040
in is viable and the screen is initialized.

04:20.550 --> 04:23.070
So what we can do is go back to this void.

04:23.080 --> 04:27.210
Look, here we get a new distance if new distance available.

04:27.210 --> 04:30.860
So we said deflect false and we get the ultrasonic distance.

04:30.870 --> 04:33.540
So we will get a distance in centimeters.

04:33.750 --> 04:39.180
And here what we want to do is to print the distance on the LCD screen.

04:39.550 --> 04:45.660
And we also want first to print the rights of a frequently we receive the data.

04:46.230 --> 04:51.660
OK, so let's suppose that this right here is not going to change in the code.

04:51.690 --> 04:56.610
So what I'm going to do is here in the setup density print.

04:57.270 --> 05:04.260
So I'm going to the LCD sets Kissack with zero and zero, which actually I don't need to do.

05:04.260 --> 05:10.380
But just so it's clearer in the code and I'm going to print reads.

05:12.310 --> 05:21.070
And then Anthony screens, I'm going to take the view here, which is ultrasonic trigger delay and put

05:21.070 --> 05:24.730
it here and then I'm going to actually print.

05:26.410 --> 05:29.730
We've space and and as for this.

05:31.160 --> 05:36.080
So the first line we have the right and as you can see, if you print, print and print everything,

05:36.080 --> 05:38.710
the cursor will be moved.

05:38.720 --> 05:43.300
OK, if I don't, said the cursor, every time I bring the cursor, we automatically be moved.

05:44.000 --> 05:51.260
Let's just upload this to be sure that the LCD working and that we have the right print in here.

05:53.050 --> 06:03.490
And OK, we see right, 60 and 60 milliseconds, so if we ever change it, that then when we start the

06:03.490 --> 06:05.550
problem again, we are going to have a different view here.

06:06.070 --> 06:06.430
Great.

06:06.850 --> 06:19.360
Now let's create a new function here, void brains, distance on LCD and double distance.

06:21.010 --> 06:25.740
So in this function, we are simply well, this function is pretty self-explanatory.

06:25.750 --> 06:28.480
We are going to take this and printed on the.

06:29.350 --> 06:37.350
So what I'm going to do, I'm going to do first LCD sit just so zero and then one.

06:37.780 --> 06:40.990
OK, the first column, the second line.

06:41.440 --> 06:44.340
And I'm going to bring as print.

06:47.180 --> 06:49.250
These tents like this.

06:50.660 --> 06:59.450
And as brain, so that with brains after, so the cursor will be here and not here, brain distance.

07:00.490 --> 07:02.120
OK, let's check here.

07:02.140 --> 07:04.990
Actually, the length of the train.

07:05.020 --> 07:09.960
OK, we have one, two, three, four, five, six, seven, eight, nine, 10.

07:10.000 --> 07:12.040
We already have ten characters for this.

07:12.370 --> 07:15.160
So let's say we have so we have 10 here.

07:16.360 --> 07:20.650
Let's say now we have the maximum, which is four hundred, you will have this.

07:21.900 --> 07:29.350
So 10, 11, 12, 13, 14, 15, 16, so that's the max value.

07:29.820 --> 07:36.020
I mean, we've in the hundreds sort of three numbers here, we not take more than 16 characters now,

07:36.060 --> 07:38.420
let's say with just four centimeters.

07:38.760 --> 07:43.270
Well, the thing is that we we need to add two spaces to this.

07:43.560 --> 07:44.160
Why is that?

07:44.170 --> 07:48.550
Because simply this string will be shorter than the previous one.

07:48.990 --> 07:50.880
Let's say you go from four hundred to four.

07:51.240 --> 07:56.040
So if you bring a string shorter than the previous one, we have seen in the previous activity that

07:56.040 --> 07:59.860
it's not going to replace all the nine, but only the characters here.

08:00.120 --> 08:05.310
So you may have some weird characters or some additional characters at the end of the line.

08:05.880 --> 08:07.000
So what we can do here?

08:07.020 --> 08:08.960
So different choices.

08:09.420 --> 08:13.650
The easiest one is entity print and add just.

08:14.640 --> 08:23.280
Two spaces, OK, which means that for this case is going to be at 16 characters and for this case it's

08:23.280 --> 08:30.360
going to be at 18 characters, but if you tried to bring out 18 characters, simply the first 16 would

08:30.360 --> 08:30.910
be printed.

08:31.230 --> 08:32.400
So that's not a problem.

08:32.730 --> 08:33.090
All right.

08:33.930 --> 08:40.380
The next solution will be just to create string objects, to put this into the string and then to do

08:40.380 --> 08:44.780
a follow up on the string to check if you need to add or not spaces.

08:44.790 --> 08:50.010
But here, it's really easy to do that, and that's not going to make any problem in the project.

08:50.310 --> 08:50.630
All right.

08:50.640 --> 08:52.760
So this function is actually pretty simple.

08:52.920 --> 08:55.510
We said the kuso and then we print some text.

08:56.080 --> 08:59.730
Now, let's call this in here.

09:01.490 --> 09:09.350
With distance, and that's pretty much OK, we have the function that we call here, whenever we get

09:09.350 --> 09:16.690
the distance, we update the LCD display screen and let's upload the code to see if it works.

09:18.100 --> 09:23.920
So you can see on the first line, we have great 60 milliseconds and on the second line we have the

09:23.920 --> 09:29.640
distance in centimeter that is updated every so 60 milliseconds.

09:29.860 --> 09:33.490
So not it's one hundred thirty eight, which is the wall behind me.

09:33.700 --> 09:41.080
I'm going to put my hand here and you can see it's going to be at 11 centimeters.

09:41.320 --> 09:42.550
I go closer.

09:42.550 --> 09:43.810
You can see my hand on the screen.

09:45.370 --> 09:49.870
We are at here six or seven centimeters.

09:49.880 --> 09:52.000
OK, so it's walking.

09:52.360 --> 09:57.420
And no, you don't need to use the same monitor or any daybook tool from the original.

09:57.640 --> 10:01.860
You can directly get the feedback from the sensor on down in the world.

10:02.170 --> 10:09.460
So that's actually the first point where you can get such a feedback without doing anything with your

10:09.460 --> 10:10.010
computer.

10:10.270 --> 10:13.600
So now you could just, for example, power on your in the world.

10:14.110 --> 10:20.800
The code will be running on the ordinary both directly and you can just see the distance on the LCD

10:20.950 --> 10:21.290
screen.

10:21.290 --> 10:23.840
No need to open, for example.

10:24.160 --> 10:24.580
All right.

10:24.580 --> 10:26.550
And that is the end of this activity.
