WEBVTT

00:00.240 --> 00:05.820
This is the solution of the previous activity where you need to make an energy drink and actually choose

00:05.820 --> 00:08.160
the delay from cellular communication.

00:08.220 --> 00:14.280
So from what you receive, in the end, you also need to validate that user.

00:14.640 --> 00:17.220
So first things first.

00:17.220 --> 00:27.600
I'm going to create a defined here and then let's use the pin to have the right entity in the set,

00:27.600 --> 00:28.640
the function.

00:28.650 --> 00:30.960
I'm going to initialize the cell communication.

00:32.500 --> 00:39.550
The one hundred fifteen thousand two hundred bothered issues that worry you and I'm going to also do

00:39.550 --> 00:40.660
say that said.

00:42.180 --> 00:42.900
Time out.

00:43.860 --> 00:46.200
With ten milliseconds.

00:47.090 --> 00:50.460
So that we are not stuck too long in the past in function.

00:50.870 --> 00:55.840
And then, of course, I need to do spin mode and.

00:57.440 --> 01:00.140
Being with about.

01:02.030 --> 01:07.730
So I have initialized Saola communication and I have initialised demoed for Spin of the eight.

01:08.450 --> 01:17.570
Now let's create this very simple building code, digital right in with high.

01:19.550 --> 01:29.310
DeLay, so let's delay empty digital right energy in low and keep the delay empty.

01:31.680 --> 01:36.000
We need to give a value for the delay.

01:36.270 --> 01:38.500
I'm not going to hardcourt these for you.

01:38.880 --> 01:42.160
We're going to use a variable that I'm going to create here.

01:42.780 --> 01:47.370
Let's put it in the jar because we want to value between one hundred and one thousand.

01:47.370 --> 01:48.810
So that's good.

01:48.990 --> 01:54.150
We are not going to overflow the integer and it's a blink delay.

01:55.910 --> 01:59.720
And we are going to initialize the value to, let's say, five hundred.

02:01.080 --> 02:05.970
So not Lindela is what I'm going to use in the delay here.

02:06.840 --> 02:15.220
All right, so we have a basic living example and know what I'm going to do here is check if we have.

02:15.240 --> 02:18.360
So if say that the label.

02:21.760 --> 02:22.920
Greater than zero.

02:24.590 --> 02:33.110
So if we have received some data, this is a translation of that, we are going to do it so the data

02:33.200 --> 02:33.830
will be.

02:35.590 --> 02:39.340
They'll let us eat.

02:40.980 --> 02:48.120
And then what are we can do is we can put the data inside the building, delete the what we've received

02:48.150 --> 02:53.700
from the past and we put it in the blink delete, which we've changed to delete for the rest of the

02:53.700 --> 02:54.140
program.

02:54.630 --> 02:57.900
But before that, we are going to validate the data.

02:58.530 --> 03:06.840
So if data is greater or equal than one hundred and.

03:07.890 --> 03:09.180
With the two ampersands.

03:10.090 --> 03:17.680
Data is lower of equal than 1000 then we can do what we want.

03:17.710 --> 03:20.730
I'm going to add parentheses here to make it clearer.

03:27.310 --> 03:31.900
So he had the first condition, is the data greater or equal than one hundred?

03:32.320 --> 03:35.970
The second condition is data lower or equal than one thousand.

03:36.310 --> 03:38.800
And we put and between the two.

03:39.260 --> 03:43.250
So the two conditions must be true for it to be true.

03:43.270 --> 03:47.220
So if we send 50, this will be false.

03:47.590 --> 03:50.710
This would be true, but the result will be false.

03:51.040 --> 03:54.490
If we send two thousand, this would be true.

03:54.730 --> 03:57.730
This would be false and the result is false.

03:58.000 --> 04:03.820
But if we send, let's say, eight hundred in both conditions are true and the result is true.

04:04.420 --> 04:11.260
So if we have validated the user inputs, we can say the delay.

04:12.370 --> 04:14.170
Is now equal to data.

04:15.140 --> 04:22.380
So let's say we send four hundred, OK, we have the type of available we received the data pass it

04:22.880 --> 04:28.670
data becomes 400, we validate the data and then blink, delay becomes four hundred, and then we do

04:28.670 --> 04:29.580
delete 400.

04:30.260 --> 04:36.350
And here again, we have a small problem is that we only be able to change the delay at this point of

04:36.350 --> 04:36.990
the program.

04:37.010 --> 04:43.940
OK, we can't change the delay between those two states, OK, because the sale that pass, it will

04:43.940 --> 04:46.790
only happen at this line of the code.

04:46.800 --> 04:50.600
So once you are here, you do need it right away.

04:50.630 --> 04:55.550
So this will not program and then you do digital right now.

04:55.580 --> 04:58.120
You wait again and then you can change the delay.

04:58.160 --> 05:00.770
You can't change the delay between those two.

05:01.130 --> 05:03.950
So what I'm going to do, I'm just going to change this a little bit.

05:04.300 --> 05:07.330
OK, so let's say it.

05:08.240 --> 05:11.790
And in the end, let's start with low.

05:12.350 --> 05:21.710
OK, and here instead of this block of code and we to do if a date is low.

05:23.830 --> 05:25.690
And what we do is we change it to.

05:28.400 --> 05:28.730
I.

05:32.230 --> 05:39.220
OK, and and so it means the state is high because there are only two states.

05:39.640 --> 05:42.690
Eighty eight is low.

05:43.570 --> 05:45.820
What would happen here this time?

05:45.820 --> 05:51.160
The state is low, so we enter the blueprinted if this condition is true.

05:51.910 --> 05:59.140
And then we put the states too high and we exceed the complete stranger, we go back to the beginning

05:59.140 --> 05:59.650
of the loop.

06:00.310 --> 06:03.950
Now, energy state is high, so this is false.

06:04.540 --> 06:10.660
We go in the end and then we set back the energy state to low and then we come back again and this is

06:10.660 --> 06:12.580
true, et, etc..

06:13.450 --> 06:21.100
So what we are going to do with that is simply go digital right in with any.

06:24.560 --> 06:25.430
And then delay.

06:26.730 --> 06:27.120
We.

06:28.330 --> 06:32.620
They did it and I can remove all of that.

06:36.180 --> 06:43.080
OK, so this way, the result here is exactly the same, but we are going to be able to receive data

06:43.080 --> 06:48.210
from sale between each change of state for the.

06:49.670 --> 06:56.630
And let's applaud the program to the arena, so let's limit activity eight.

06:57.710 --> 07:02.820
They and the program is imploding, so we also verify that the competition is working.

07:02.840 --> 07:03.200
Yes.

07:03.680 --> 07:10.630
And you can see so the ADC, the first one is blinking every five hundred milliseconds.

07:11.030 --> 07:12.740
So quite a normal behavior.

07:13.310 --> 07:17.810
Now, I'm going to open the sale monitor and let's try to send a different venue.

07:18.400 --> 07:22.600
Let's try to send two hundred and let's see what happens.

07:22.610 --> 07:28.850
So I press enter and you can see now the energy blinks much faster.

07:29.810 --> 07:33.050
OK, now let's go back to five hundred.

07:34.700 --> 07:37.280
OK, links are the five hundred milliseconds.

07:38.360 --> 07:46.280
Now, let's put one down, which is the maximum, and you can see the energy blinks at one thousand.

07:47.870 --> 07:50.270
Let's go back to the minimum, which is one hundred.

07:53.170 --> 07:54.370
At one hundred.

07:56.280 --> 07:59.580
OK, so you can modify the value any time you want.

08:00.030 --> 08:00.290
OK.

08:02.500 --> 08:12.600
Now, if they decided to build, let's say, 3000 or three seasons center and you can see nothing changes

08:12.600 --> 08:12.610
it.

08:13.820 --> 08:20.450
Because here in the program, we have validated the data so we can only give values between one hundred

08:20.450 --> 08:29.210
and one thousand six hundred, we won't pay if I tried to give to that network work and we still have

08:29.210 --> 08:31.310
the 600 millisecond delay.

08:33.400 --> 08:35.360
So that is working quite well.

08:35.500 --> 08:41.860
OK, but actually there is a small issue here with the timing, that may be a real problem depending

08:41.860 --> 08:43.710
on what you want to do with your application.

08:43.990 --> 08:52.650
So let's say you have put the lead delay to one thousand and then you sent another delay to one hundred.

08:52.660 --> 08:55.420
So you want to change from one thousand two hundred.

08:55.750 --> 09:02.140
The thing is that so when you use delay with one thousand, this will block the program for one complete

09:02.140 --> 09:02.440
signal.

09:02.920 --> 09:03.310
All right.

09:04.090 --> 09:11.240
Let's say you send one hundred when the program has just entered the delay with one signal.

09:12.040 --> 09:17.290
What will happen is that your data that you sent will be processed.

09:17.590 --> 09:24.700
But after one second, OK, because first the delay will happen and then you will be able to read the

09:24.700 --> 09:30.850
data that the Ardino has received, which means that when, for example, you have the delay, which

09:30.850 --> 09:38.710
is one second and you want to change to one hundred millisecond, you may have to wait up to one single

09:38.920 --> 09:42.520
one thousand millisecond so that the change can be effective.

09:42.730 --> 09:44.120
And that may be quite a problem.

09:44.550 --> 09:50.920
Don't know, let's say, but the maximum I'm going to give you an example for the maximum at four thousand.

09:50.930 --> 09:52.510
So that would be for Siggins.

09:54.230 --> 09:57.460
And when you say a monitor, I send for town.

09:58.220 --> 10:05.450
OK, so now the power of, as you can see, power, I'm going to get one hundred and wait until the

10:05.450 --> 10:06.260
end is put off.

10:06.260 --> 10:07.280
OK, send one hundred.

10:08.240 --> 10:15.110
And what happens is that the it is pulled off did for about four seconds and then the value changes.

10:15.370 --> 10:16.520
OK, so.

10:17.970 --> 10:24.420
That was the problem that I was talking about and, well, good news, because that's exactly what we

10:24.420 --> 10:27.030
are going to solve in the next section.
