WEBVTT

00:00.180 --> 00:05.700
This is the solution of the previous activity where we agreed to improve the current program we have

00:06.060 --> 00:11.390
so that we can make it, the three entities blink and stop when we press the button.

00:11.760 --> 00:15.440
So we have quite a few things to do, but let's start step by step.

00:15.450 --> 00:19.000
So first, we already have our Dippin right here.

00:19.310 --> 00:22.520
OK, I'm going to work on the set up function first.

00:22.990 --> 00:23.220
Right.

00:23.340 --> 00:27.990
So following the setup, we have four p.m. and three digital.

00:27.990 --> 00:28.290
Right.

00:28.990 --> 00:32.210
So the ping button doesn't change in here.

00:32.400 --> 00:37.480
Instead of using Benmore three times what I'm going to use a full.

00:41.320 --> 00:50.320
That at zero and then I and we want to continue wide eyed is typically lower than the size of discovery.

00:50.650 --> 00:52.980
I'm going to I less pass.

00:54.900 --> 01:02.880
So it will start at zero and then one and then two, and when it arrives at three, three, which is

01:02.880 --> 01:03.770
out of the great.

01:04.740 --> 01:13.080
Then this condition is false and then we exit the fall, so as a reminder, here we have index zero,

01:13.080 --> 01:18.090
index one, an index to we start to count at zero.

01:18.090 --> 01:25.590
And then when you have so when you have the size of the array or the index, you have to stop at the

01:25.590 --> 01:30.570
size minus one because we have historically lower than.

01:32.020 --> 01:36.610
We will stop at the site, minus one, what we do in Moad.

01:38.350 --> 01:44.700
And then so we need to find the PIN number and PIN number is actually inside the area.

01:45.270 --> 01:47.950
We are going to write the name of ring in.

01:49.210 --> 01:49.590
All right.

01:50.170 --> 01:52.960
We've brackets in the brackets.

01:52.960 --> 01:57.880
We're going to give the index and then I'll put.

01:59.440 --> 02:07.870
So this will first, though, this will be I would be zero, so it will be one thing just like we did

02:07.870 --> 02:11.940
here and then energy two and three and that's it.

02:12.280 --> 02:13.240
But we can remove.

02:14.330 --> 02:18.480
So three lines here and now the call is actually much clearer.

02:18.540 --> 02:22.120
OK, we just use Benwood once and that's it.

02:22.520 --> 02:24.410
The weather, we have three inches.

02:25.070 --> 02:25.610
Two hundred.

02:25.610 --> 02:27.320
And it is we have the same coat.

02:28.950 --> 02:39.330
And let's put this into a function, it void set in mode, so we create a function, we void because

02:39.330 --> 02:43.600
we don't return anything, we don't require any parameter.

02:43.670 --> 02:50.260
OK, we are simply going to use directly the array inside the function.

02:50.280 --> 02:54.120
OK, and what we can do is simply take this.

02:56.420 --> 02:57.830
Up and set it there.

02:58.520 --> 03:08.360
So this is our function, which will set the spin mode and then of course this function alone will not

03:08.360 --> 03:08.900
do anything.

03:08.930 --> 03:13.340
This is just a block of code that you declare and that can be used.

03:13.350 --> 03:16.670
But if you don't use it, well, it's not going to do anything.

03:17.210 --> 03:23.210
So in the setup function, we call the function set in mode.

03:23.900 --> 03:24.310
All right.

03:24.680 --> 03:27.650
And now let's do the same thing with this block of.

03:27.950 --> 03:30.770
So I'm just going to create a function directly.

03:32.540 --> 03:35.680
Then of all ages.

03:37.770 --> 03:40.540
And we're going to do a full also.

03:42.750 --> 03:48.690
Start at zero and then I is typically lower than the average size.

03:48.930 --> 03:49.860
That is the same.

03:51.270 --> 03:52.270
A plus plus.

03:53.040 --> 03:57.620
All right, the ones you know how to go through an all right, well, the follow doesn't change.

03:57.630 --> 03:58.480
It's always the same.

03:59.310 --> 04:02.070
And then digital rights.

04:02.760 --> 04:07.710
And in theory, I just like it here.

04:09.260 --> 04:10.370
And then simply load.

04:12.240 --> 04:17.430
And this function will turn off all the entities, just like the name suggests.

04:18.030 --> 04:23.550
So what we can do now is simply call the function of both entities.

04:25.630 --> 04:30.310
And let's not forget this semicolon, OK, when you call a function.

04:31.810 --> 04:33.040
You don't need them.

04:33.060 --> 04:39.780
OK, don't put a semicolon after you declare a function with the definition of the function in the block,

04:40.710 --> 04:45.680
but when you call them, have to use the semicolon and let's just remove that.

04:46.560 --> 04:49.550
And as you can see, our set of code is no much clearer.

04:50.100 --> 04:53.830
And this will work whether you have three of 10 or more entities.

04:54.330 --> 04:54.740
Great.

04:55.350 --> 04:59.970
So now let's handle the loop function in the loop.

05:00.000 --> 05:06.990
We are still going to use the digital arena check for a pushbutton, OK, but we simply want to remove

05:06.990 --> 05:09.280
all of the digital rights as well.

05:09.460 --> 05:09.700
OK.

05:10.990 --> 05:13.270
I'm going to create a function here.

05:15.060 --> 05:18.330
Which name is what do they say to these?

05:20.690 --> 05:23.750
OK, and so void as well.

05:23.790 --> 05:27.860
OK, because this is a function to execute an action, not to return something.

05:29.320 --> 05:34.750
And then I'm going to copy that you.

05:36.270 --> 05:43.680
The controlled explosion cut and then put it here, as you can see, the indentation is completely wrong.

05:44.100 --> 05:45.390
So what I can do is.

05:46.440 --> 05:49.860
I select everything in it it.

05:51.050 --> 05:54.150
You can you can see increase or decrease the indents.

05:55.230 --> 05:58.790
For example, we shift and double and decrease it.

06:00.290 --> 06:07.550
Going to do this, that we have to in addition, here or here, that's all right.

06:07.550 --> 06:11.900
I know here I'm simply going to call the function.

06:15.100 --> 06:22.810
So let's see if everything is correct in the total dysfunction, so we take the blink states, OK,

06:23.080 --> 06:25.300
this viable is it?

06:25.800 --> 06:27.850
But in a more global scope, we can use it.

06:28.990 --> 06:34.690
If it's one, then we simply do our business here I how we change the state.

06:35.230 --> 06:38.020
So the next time we enter the function, the state is changed.

06:38.020 --> 06:45.880
And instead of going here we go else and we do this, but we change the blink rate for it.

06:45.930 --> 06:46.330
It is.

06:46.330 --> 06:51.780
And then we change the variable to go back to one the next time we call it a function.

06:51.970 --> 06:55.860
And of course after that we wait for three hundred milliseconds.

06:56.140 --> 07:01.840
Actually, this maybe instead of putting here, I'm going to put it there.

07:05.140 --> 07:11.020
The total LSD is just in charge of doubling the and it is then in the loop.

07:12.180 --> 07:16.680
We had the delay so we can change the delay outside of this function.

07:17.710 --> 07:24.440
In the loop, we only have it if the button is not pressed, we took all the ladies and we wait three

07:24.440 --> 07:25.360
hundred milliseconds.

07:26.250 --> 07:26.850
All right.

07:26.960 --> 07:32.830
And now you can see that we have some valuables here for initialization.

07:33.200 --> 07:34.520
We have some constants.

07:35.180 --> 07:37.490
We have one, two and three functions.

07:38.560 --> 07:45.700
And in the setup, we only have three lines of code and in the loop we only have four lines of code,

07:46.240 --> 07:47.780
so that's actually much better.

07:48.250 --> 07:54.250
The one thing here is that actually by doing which we did in this activity, we increased the total

07:54.250 --> 07:55.950
number of lines in the program.

07:56.050 --> 08:03.640
OK, the program may seem a little bit more complex, but the truth is that it's actually much less

08:03.640 --> 08:08.290
complicated because the setup is very minimal.

08:08.410 --> 08:09.880
The loop is very minimal.

08:10.180 --> 08:15.550
And then the functions will allow you to easily change the behavior of your program.

08:15.940 --> 08:18.520
So now we have three entities.

08:19.000 --> 08:23.500
If they want to add a fourth entity, I just need to add a defined here.

08:24.040 --> 08:29.800
But it's a defined entity for PIN nine and then change here to four.

08:30.550 --> 08:34.330
Add the eight to the array and.

08:34.780 --> 08:37.040
Well, this doesn't change.

08:37.240 --> 08:38.590
This doesn't change.

08:39.780 --> 08:46.950
The setup and the loop don't change either, we just change also here, the 80s, but it's much more

08:46.950 --> 08:53.730
easier to handle and everything we did here, creating functions, using full loops, going through

08:53.730 --> 08:59.310
arrays, etc. We are going to use them, of course, in the following of these calls and you are going

08:59.310 --> 09:02.000
to use them in many projects that you create.

09:02.160 --> 09:02.540
All right.

09:02.560 --> 09:05.400
And of course, let's test the program.

09:05.410 --> 09:06.840
So I'm going to verify it.

09:09.440 --> 09:10.310
Number seven.

09:12.800 --> 09:19.010
OK, and let's applaud code to see if we are not wrong with what we need and if we have the exact same

09:19.010 --> 09:25.550
results and yes, it seems that it's working the exact same way as before.

09:26.030 --> 09:26.390
All right.

09:26.390 --> 09:31.390
So that's the end of this activity and that's also the end of the first part of the.

09:31.790 --> 09:32.870
So congratulations.

09:32.870 --> 09:38.870
You have not seen all the basic stuff you need all the basic hardware functionalities to be able to

09:38.870 --> 09:40.330
create more complex program.
