So now what is the problem with delay?
We're going to come back to the solution of the previous activity when we used the cell communication.
So that is activity number eight going to open that code here.
And go back to here.
So I have provided a few explanation already on the solution for the activity, but I'm going to give
more details now than I understand clearly what DeLay does.
DeLay will simply stop the execution of the program for a certain amount of time.
And in this program, you have seen that when we are in the delay, well, we can't actually do anything
else.
OK, so here we decided communication.
When you send cellular data from your computer to the you know, the hardware of the area will actually
receive the data and it will be ready to be passed.
OK, but because you use a delay.
Well, if you use a delay for here four thousand milliseconds, then the thing is that if you receive
any data before the end of the delay, you will have to wait for the end of the delay to actually be
able to process the data.
So what does this means is that if you use the delay function, basically you can just do one thing
at a time.
If you try to do two things like here blink an energy and the data from the sale, well, you can say
you have a timing problem because you are not able to read the data as soon as it arrives, at least
with very small timing delay.
And there are many examples where the delay function will block you from doing what you want.
For example, let's say you want to make two blinks, OK, here we have one blink, but let's say you
want to make two energy blinks at different rates.
So the first lady, for example, with blink every four hundred milliseconds and the signal that you
will blink every eight seconds.
OK, how can you actually do this?
Because if you blink every eight seconds, it means you have to write a delay of eight seconds and you
have to block the program for eight seconds, which means you are going to be so late when reading the
cell, you might even miss some data, which means also that you can't make the other blink every one
hundred milliseconds.
So the only solution, if you want to keep using delay, is to split the program in many different parts,
OK, with more delays and that will quickly become a huge mess.
And another example, let's say you have one entity that is blinking every two seconds and then you
want to measure some data from a census.
So, for example, you want to measure the distance from an object with another sensor.
That's what we are going to do in the following of these schools.
And if the object is to close from the sensor, you are going to put on another energy to make sure
that the user knows that there is an obstacle in the way.
The thing is that with the energy that blinks and things, well, you would only be able to read the
sensor every two seconds.
So it means you will be late by telling the user that there is an obstacle and that can be a real problem
for your application.
So that's just a few examples.
And if you already have tried to make programs by yourself with more than just one thing in your program,
OK, we have multiple tasks, then you may have seen also that you are quite limiting by using this
delay function, because the thing is that on an hourly no, it's not like a normal computer when you
can have what we call multi training and that you can have multiple actions that run in parallel.
So that would not be a problem here.
You have just one action at the time.
You can only execute one instruction at a time.
So if you block, we delay.
Anything else can't be executed.
So that is the problem.
And the good news is that there is a solution to that using other time functionalities of the idea that
we are going to see right now.