WEBVTT

00:00.210 --> 00:06.240
This is the solution of the previous activity where you need to make three, it is being in a certain

00:06.240 --> 00:08.490
way and then change the current state.

00:08.490 --> 00:14.760
And if the president is pressed, you just stop the sequence and then you resume when the push button

00:15.030 --> 00:16.100
is not pressed anymore.

00:16.530 --> 00:21.270
So I'm going to first initialize all the things here.

00:21.600 --> 00:26.940
We've defined the one in which is number 12.

00:28.530 --> 00:31.500
And the two in number 11.

00:34.000 --> 00:43.510
And being which is number 10 and then we have we are going to use the push button to button.

00:44.560 --> 00:48.310
Dean, which is on digital being number two.

00:49.430 --> 00:51.350
OK, so we have our full.

00:52.390 --> 01:00.910
Things right here, so not in the set of what we can do is initialise we've been moved, so I'm going

01:00.910 --> 01:03.400
to initialize the Berlanti first.

01:04.900 --> 01:14.440
We have an input Motoki, because we are going to read from that thing because this is essential and

01:14.440 --> 01:22.750
then the buying mode for the one in which is output and I'm going to do the same.

01:24.090 --> 01:26.510
For eighty two, end the.

01:27.870 --> 01:31.530
Treat it as well as initialise.

01:32.610 --> 01:37.820
State property one below.

01:38.920 --> 01:39.580
And then.

01:41.050 --> 01:42.230
Two and three.

01:43.650 --> 01:44.830
But we have our city.

01:45.480 --> 01:49.840
OK, so nothing really new here and now in the ocean.

01:50.010 --> 01:51.720
I'm going to remove all that.

01:52.200 --> 01:55.820
I'm going to make the first state of the blink.

01:55.950 --> 02:04.200
OK, so digital rights, any one in will be high, OK?

02:04.650 --> 02:05.190
The.

02:07.090 --> 02:13.120
So the energy to will be low and then the.

02:14.550 --> 02:17.670
Digital right, Eighty-three?

02:19.140 --> 02:24.330
Will be high, so we have high, low and high.

02:26.550 --> 02:36.870
And then so this is a typical link, we use a delay of three hundred milliseconds and then we can simply

02:36.870 --> 02:38.130
say, I'm going to just.

02:39.880 --> 02:46.060
This isn't just in this state low.

02:47.560 --> 02:47.870
I.

02:49.980 --> 02:54.240
And and then, of course, we need to wait another three hundred.

02:55.470 --> 03:00.750
Milliseconds, OK, because the program will simply go from there to the beginning of the loop.

03:01.090 --> 03:08.820
OK, but if we don't use the delay this we can CDC to directly go back to the state.

03:09.240 --> 03:09.620
All right.

03:09.630 --> 03:11.780
So the brink is finished.

03:12.210 --> 03:14.850
That is the first step of this mini project.

03:15.260 --> 03:20.080
But now how are we going to stop that from the president?

03:20.670 --> 03:27.890
Well, we would need, of course, to use the digital read function we've done.

03:29.880 --> 03:31.530
So that is for sure.

03:31.560 --> 03:34.760
So we need to use that to get the state of the button.

03:35.130 --> 03:39.990
And now, because we want to check if the push button is pressed, then we are going to use and if.

03:41.310 --> 03:48.370
If digital read button thing is equal with two equal signs, they're important, too.

03:48.800 --> 03:51.170
I think if the president is priced.

03:52.290 --> 03:54.510
Then what we are going to do?

03:55.470 --> 03:57.570
Is, well, simply nothing.

03:57.720 --> 03:59.730
OK, and it's.

04:01.820 --> 04:05.150
Let's put that here in the end.

04:05.160 --> 04:11.870
So if you copy and paste in a block, the indentation may be wrong, so you just fix it.

04:11.870 --> 04:19.880
So, for example, I select all of that and I press dub once and it automatically adds to notation,

04:20.150 --> 04:22.670
which is much nicer to read.

04:23.460 --> 04:27.620
But what we do here in the program is we check everything into the loop.

04:27.990 --> 04:31.310
We check if the button is pressed, if we do nothing.

04:31.850 --> 04:34.760
And if the button is not pressed, we execute the.

04:35.690 --> 04:41.870
And the first thing you may have noticed here is that instead of doing if this condition is true, we

04:41.870 --> 04:42.920
do nothing else.

04:42.920 --> 04:45.380
We do something we can directly check.

04:46.620 --> 04:52.140
If the growth is low and then we simply do the blink.

04:53.020 --> 04:57.240
And well, the reason is because we don't do anything else.

04:57.930 --> 05:04.840
So here we are only going to enter the look of code and we are only going to make the editors blink

05:05.020 --> 05:10.900
when the push button is not pressed because so whenever the push button is priced, we simply don't

05:10.900 --> 05:12.060
enter this book of code.

05:12.550 --> 05:19.000
And then you might see another problem is that so if the pushbutton is not pressed, which we are going

05:19.000 --> 05:20.590
to do is to we enter that.

05:20.590 --> 05:22.900
If so, we make the error.

05:22.900 --> 05:29.740
It is so high, low, high, and then the delete 300 segments and then it is low, high, low delay

05:29.740 --> 05:30.580
300 seconds.

05:30.760 --> 05:34.170
And then and only then we check the button again.

05:34.630 --> 05:40.690
So you will not be able to pull the program here between those two states.

05:41.350 --> 05:44.870
You will only be able to push the program after this date.

05:44.890 --> 05:50.620
So after we go back here, but not at this point, what are we can do here?

05:51.370 --> 05:57.840
Well, first, the maybe most obvious solution is we can split this into two.

05:57.870 --> 06:06.040
If so, I'm just going to finish the F here and add another, which is the exact same.

06:07.080 --> 06:07.980
It right here.

06:08.340 --> 06:09.930
So first we check.

06:11.170 --> 06:13.060
And actually, let's put a delay here.

06:15.810 --> 06:21.750
But we have two blocks of code that are saying, OK, but just with a different state, OK, for the

06:21.750 --> 06:27.540
bridge, the first we check, if the bottom is not priced, if the button is not pressed, then we just

06:27.540 --> 06:29.670
execute this eight of the.

06:30.420 --> 06:34.320
We wait for three hundred milliseconds and then we check again the button.

06:34.880 --> 06:41.000
So if let's say we executed this, but then we press the button, then this will not be executed.

06:41.430 --> 06:43.970
And then we come back and we continue to check it.

06:44.100 --> 06:48.450
But this is not a good solution because, well, you need to write the same structure twice.

06:48.900 --> 06:54.430
And then depending on when you press the push button, you may execute the same structure twice.

06:54.450 --> 06:57.080
So let's say you execute that one, OK?

06:57.420 --> 07:00.750
And you in this three hundred milliseconds, you press the button.

07:00.780 --> 07:03.770
So this will be false.

07:03.780 --> 07:07.880
And so we don't enter this book of code and then you continue to check at full speed.

07:07.890 --> 07:13.680
And then when you release the button, if this is the first line that gets executed, you are just going

07:13.680 --> 07:17.700
to execute that a second time instead of just going to the next one.

07:18.360 --> 07:26.400
So what I'm going to do is simply to use just one if but I'm going to check the state of the brain inside.

07:26.580 --> 07:34.350
If so, we are going to use a variable here that I'm going to make it global so we can create it here.

07:34.350 --> 07:35.880
We can use it in the loop.

07:35.880 --> 07:40.990
And because it is in a more global scope, the value will stay in the book.

07:41.130 --> 07:43.080
It just creates a viable in the loop.

07:43.320 --> 07:49.400
Every time we go out of the loop, the variable will be gone and then we can't keep the volume.

07:49.890 --> 07:57.810
So let's name it any linked states and just going to initialize it to let's say one.

07:58.080 --> 08:02.850
OK, let's say we have the state one and the state to.

08:05.100 --> 08:11.020
Let's just focus on that first issue, which will become the only if if the button is not pressed so

08:11.040 --> 08:20.040
we don't change that, then we are going to check if every state is equal to one.

08:21.780 --> 08:32.850
So that was, let's say the current state was one, what we do is we do think states is equal to two.

08:32.860 --> 08:34.620
So here we check.

08:35.680 --> 08:42.800
The value with to equal, so this will simply compared to value and return true, if this is correct,

08:43.130 --> 08:49.330
this is equal and here we assign a new value with just one equal to the state.

08:49.960 --> 08:52.820
So let's say that we are going to execute that first year.

08:52.960 --> 08:53.340
OK.

08:55.680 --> 09:02.400
So, Ellie, dimpling state one, we execute this and then we change the variable.

09:03.590 --> 09:11.150
To do so the next time we enter the look and the if, then the eligible state will not be equal to one,

09:11.150 --> 09:18.890
but to do so, we can use else and he could write as a state is equal to two.

09:18.890 --> 09:22.570
But because there is only two states we can just use as.

09:24.070 --> 09:25.960
And going to right now.

09:27.000 --> 09:27.990
This year.

09:31.280 --> 09:39.740
So the second state is the first state to second state and now I'm going to put any link, eight is

09:39.770 --> 09:41.180
equal to one.

09:42.230 --> 09:49.810
OK, and just remove all that and what I'm going to keep is the delay that I'm going to write the delay

09:49.940 --> 09:51.260
only once.

09:53.040 --> 09:56.560
And actually, we are missing a three bracket.

09:56.610 --> 09:58.890
OK, so make sure you have all the brackets.

09:59.160 --> 10:04.710
This is also a common error, is that you are missing a bracket and then you may have some errors that

10:04.710 --> 10:04.920
we have.

10:04.920 --> 10:09.870
The brackets here, you can see with the look and then the fist if they get them.

10:10.530 --> 10:18.430
This if from here to there and then else and then let's end the delay here is not inside this.

10:18.960 --> 10:22.280
This blog is inside the digital void.

10:22.330 --> 10:23.570
But look.

10:24.520 --> 10:30.310
So this court is, as you can see, much better because you will be able to pull the program between

10:30.340 --> 10:36.480
each state, OK, if you want, you can add other states, you can add more states easily.

10:36.490 --> 10:38.800
You just need to write delete one time.

10:39.100 --> 10:45.640
And this well, this is your first state mission in hardware for women.

10:45.640 --> 10:48.880
In Hunwick project, you would often see state machines.

10:49.180 --> 10:55.210
So basically you have available, which contains a state, OK, and then you check if the state is that

10:55.210 --> 10:59.770
particular state, you do one action and then you change the state to another one.

11:00.040 --> 11:05.470
The the next time you can tell if the state is different and you execute another action and every time

11:05.470 --> 11:07.540
you executive action, you change the state.

11:07.780 --> 11:09.580
So you change the action for the next time.

11:10.120 --> 11:13.900
OK, so to recap in the loop function, first we check for the state of the button.

11:14.170 --> 11:18.160
If the button is priced well, this is false or we don't do anything.

11:18.580 --> 11:25.690
If the button is not priced, we are going to execute the blink with either one of the two states,

11:25.690 --> 11:26.040
OK?

11:26.320 --> 11:30.490
And once we execute the state, then the next time it would be the other state.

11:30.790 --> 11:38.620
And after we execute the blink, we simply use the delay 300 to wait before we check the next time.

11:39.220 --> 11:42.730
And let's actually make this program combined here.

11:43.210 --> 11:44.230
I'm going to name it as.

11:45.210 --> 11:45.990
Activity.

11:49.730 --> 11:56.930
So let's check if we have any compañero and down company, so that seems to be good and now we're going

11:56.930 --> 12:02.360
to upload to connect your make sure it's connected, et cetera, upload code.

12:05.140 --> 12:08.000
And you can see the editors are blinking.

12:08.020 --> 12:14.440
So first one and three and then edit it to every three hundred milliseconds.

12:14.860 --> 12:18.290
So now is the text I'm going to press on the button.

12:18.880 --> 12:21.920
And as you can see here, the blink has stopped.

12:21.940 --> 12:26.280
I realize the president and the brain continues like.

12:28.190 --> 12:33.470
As the president, you can see now, it's already one and three it.

12:34.280 --> 12:39.530
Let's try to get you to win three again.

12:40.400 --> 12:45.260
And we had two so we can pull between each state of the black.

12:46.230 --> 12:48.530
All right, that's the end of this activity.
