WEBVTT

00:00.330 --> 00:03.690
So now what is the problem with delay?

00:04.140 --> 00:10.400
We're going to come back to the solution of the previous activity when we used the cell communication.

00:11.140 --> 00:17.160
So that is activity number eight going to open that code here.

00:18.630 --> 00:19.810
And go back to here.

00:19.830 --> 00:25.740
So I have provided a few explanation already on the solution for the activity, but I'm going to give

00:25.740 --> 00:30.420
more details now than I understand clearly what DeLay does.

00:30.870 --> 00:36.660
DeLay will simply stop the execution of the program for a certain amount of time.

00:37.350 --> 00:43.380
And in this program, you have seen that when we are in the delay, well, we can't actually do anything

00:43.380 --> 00:43.840
else.

00:43.860 --> 00:46.380
OK, so here we decided communication.

00:46.710 --> 00:52.680
When you send cellular data from your computer to the you know, the hardware of the area will actually

00:52.700 --> 00:56.520
receive the data and it will be ready to be passed.

00:56.580 --> 00:59.310
OK, but because you use a delay.

00:59.700 --> 01:07.240
Well, if you use a delay for here four thousand milliseconds, then the thing is that if you receive

01:07.500 --> 01:13.740
any data before the end of the delay, you will have to wait for the end of the delay to actually be

01:13.740 --> 01:15.390
able to process the data.

01:15.780 --> 01:21.960
So what does this means is that if you use the delay function, basically you can just do one thing

01:21.960 --> 01:22.440
at a time.

01:23.100 --> 01:30.180
If you try to do two things like here blink an energy and the data from the sale, well, you can say

01:30.180 --> 01:36.330
you have a timing problem because you are not able to read the data as soon as it arrives, at least

01:36.540 --> 01:38.990
with very small timing delay.

01:39.570 --> 01:45.730
And there are many examples where the delay function will block you from doing what you want.

01:45.750 --> 01:54.000
For example, let's say you want to make two blinks, OK, here we have one blink, but let's say you

01:54.000 --> 01:57.530
want to make two energy blinks at different rates.

01:58.110 --> 02:04.120
So the first lady, for example, with blink every four hundred milliseconds and the signal that you

02:04.170 --> 02:06.990
will blink every eight seconds.

02:07.390 --> 02:09.480
OK, how can you actually do this?

02:09.480 --> 02:16.590
Because if you blink every eight seconds, it means you have to write a delay of eight seconds and you

02:16.590 --> 02:23.490
have to block the program for eight seconds, which means you are going to be so late when reading the

02:23.490 --> 02:29.330
cell, you might even miss some data, which means also that you can't make the other blink every one

02:29.340 --> 02:30.240
hundred milliseconds.

02:30.720 --> 02:38.280
So the only solution, if you want to keep using delay, is to split the program in many different parts,

02:38.450 --> 02:43.460
OK, with more delays and that will quickly become a huge mess.

02:43.980 --> 02:51.720
And another example, let's say you have one entity that is blinking every two seconds and then you

02:51.720 --> 02:55.040
want to measure some data from a census.

02:55.040 --> 03:00.080
So, for example, you want to measure the distance from an object with another sensor.

03:00.090 --> 03:02.690
That's what we are going to do in the following of these schools.

03:03.180 --> 03:10.020
And if the object is to close from the sensor, you are going to put on another energy to make sure

03:10.020 --> 03:14.070
that the user knows that there is an obstacle in the way.

03:14.430 --> 03:21.690
The thing is that with the energy that blinks and things, well, you would only be able to read the

03:21.690 --> 03:23.340
sensor every two seconds.

03:23.730 --> 03:31.020
So it means you will be late by telling the user that there is an obstacle and that can be a real problem

03:31.020 --> 03:31.870
for your application.

03:32.280 --> 03:34.160
So that's just a few examples.

03:34.620 --> 03:41.520
And if you already have tried to make programs by yourself with more than just one thing in your program,

03:41.820 --> 03:48.410
OK, we have multiple tasks, then you may have seen also that you are quite limiting by using this

03:48.450 --> 03:55.470
delay function, because the thing is that on an hourly no, it's not like a normal computer when you

03:55.470 --> 04:01.180
can have what we call multi training and that you can have multiple actions that run in parallel.

04:01.200 --> 04:02.870
So that would not be a problem here.

04:03.180 --> 04:05.520
You have just one action at the time.

04:05.790 --> 04:09.180
You can only execute one instruction at a time.

04:09.510 --> 04:10.920
So if you block, we delay.

04:11.340 --> 04:13.450
Anything else can't be executed.

04:13.950 --> 04:15.480
So that is the problem.

04:15.810 --> 04:22.830
And the good news is that there is a solution to that using other time functionalities of the idea that

04:22.830 --> 04:24.300
we are going to see right now.
