WEBVTT

00:00.180 --> 00:05.940
Let's first understand what the problem is for that, they will simply start with an example where you

00:05.940 --> 00:08.460
will clearly see the button bouncing.

00:08.850 --> 00:14.880
So what we're going to do is to try to monitor the push-Button, but not just when it's high or when

00:14.880 --> 00:15.800
it's low equity.

00:15.810 --> 00:21.120
Previously, we are going to monitor the push-Button so we can detect a change of state.

00:21.910 --> 00:27.300
This is the most common use case for anybody when you detect a change of state, which means that,

00:27.300 --> 00:34.490
for example, the user presses the button so the state will go from low to high in the circuit.

00:34.500 --> 00:35.640
We have all that.

00:35.670 --> 00:39.420
You simply release the button and the state will go from high to low.

00:39.930 --> 00:45.470
And this is this exact change of state that we want to monitor, not just all the time.

00:45.480 --> 00:47.150
The button is high all the time.

00:47.160 --> 00:47.890
The button is low.

00:48.420 --> 00:54.360
Well, let's make a simple example to monitor the change of the state of the button and print it on

00:54.360 --> 00:55.200
the side of the monitor.

00:55.830 --> 01:02.620
So first, I'm going to initialize the define button in two.

01:02.710 --> 01:03.930
OK, so as usual.

01:05.700 --> 01:08.880
Because we are going to use Cyril, I'm going to say begin.

01:11.550 --> 01:14.070
It with these moderate and then.

01:15.250 --> 01:17.950
In mode, written in.

01:18.990 --> 01:19.380
Input.

01:19.680 --> 01:21.310
So nothing new here.

01:22.140 --> 01:31.160
And then in the loop function, what I'm going to do is I'm going to read digital read button thing.

01:31.610 --> 01:34.350
I'm going to read the stage from the button.

01:34.710 --> 01:40.590
Well, and if we want to be able to monitor the difference, we need to stop because the previous one.

01:40.710 --> 01:44.550
OK, how can you know that the previous volume was high and now it's low?

01:44.790 --> 01:47.400
Well, because you stored the prejudice that you had.

01:47.640 --> 01:51.000
So we are going to store it as a global valuable byte.

01:53.080 --> 02:00.160
But in states, it's initially too low that we use bait here for the state of the button because it's

02:00.160 --> 02:01.810
just low and high.

02:02.300 --> 02:07.520
So this is maybe a little bit better, but you could also use it without any problem.

02:07.540 --> 02:09.430
OK, that's not a game changer thing.

02:09.700 --> 02:15.430
If we want the same, whether you use it or just like we did previously in some previous activities

02:15.550 --> 02:22.630
and as a quick recap byte is of value from zero to two hundred fifty five and an integer contains two

02:22.630 --> 02:29.110
bytes and with two bytes you can go from minus thirty two thousand to about thirty two thousand.

02:29.920 --> 02:34.040
So now we have our reading of the button.

02:34.060 --> 02:38.170
I'm going to save it in a new variable kinetic creating the void loop.

02:38.510 --> 02:42.010
So let's say new button state.

02:43.610 --> 02:48.650
OK, so we have the new Golden State and we have the, let's say, the Buuren state, which is also

02:48.650 --> 02:49.270
the producer.

02:49.360 --> 02:51.880
OK, so we're in the neighboring state.

02:52.250 --> 03:00.560
And then what we are going to do, we are simply going to check if the new Budden date is different

03:00.710 --> 03:02.150
than the one state.

03:04.620 --> 03:09.570
And if that is the case, we are going to see that we are going to action.

03:10.850 --> 03:16.850
And angry also just before so the other head of the mirror that I'm going to do Button St..

03:18.360 --> 03:20.550
Is equal to New Bernstine.

03:21.960 --> 03:24.870
So every time we enter the loop, we check the balance.

03:25.580 --> 03:31.740
It's low first, then so it's low and then we press the button and the time that we press the button

03:31.920 --> 03:34.890
at this exact moment, this will give high.

03:35.040 --> 03:40.290
OK, we check the new Golden State is different from the previous button state because now it's high

03:40.290 --> 03:41.220
and this is low.

03:41.550 --> 03:48.510
So we enter this executive action and we store, of course, the brain state as the new one.

03:48.570 --> 03:55.080
OK, so the next time the value is high, we don't come back in this if again and we only come back

03:55.080 --> 03:57.610
in the if if the person is no low.

03:57.630 --> 04:01.620
So when we release the button again, what is the action we want to do?

04:01.620 --> 04:05.270
We want to print when the button was pressed aren't released.

04:05.610 --> 04:14.610
So here in this, if we know that the state of the button has just changed, so we know it's either

04:14.610 --> 04:20.250
pressed or either released now to make the difference, to go further, we can just check.

04:20.250 --> 04:26.130
So no button state is equal to new warranty, so we can just check any viable we can just check if the

04:26.130 --> 04:32.520
current state is high, which means that the bottom was priced.

04:33.790 --> 04:43.390
Cellulose print, Ellen Burton, Riced, and then we can use El's, so basically the burns steak is

04:43.390 --> 04:49.860
not high, which means that it is low because there are only two states in the label, Taylor Green

04:49.870 --> 04:50.410
Capellan.

04:53.710 --> 04:54.280
Release.

04:56.360 --> 05:02.360
Can we do this, we are going to have the exact moment when we press the button and when we release

05:02.360 --> 05:07.790
the button, so quick recap, we stole the previous state, our current state of the button here in

05:07.790 --> 05:09.860
a global Bible, then in the loop.

05:09.860 --> 05:14.540
Every time we read the new state, we compare the state with the previous one.

05:14.720 --> 05:22.010
If this is different, we know that something happened, that we, of course, stole the previous date

05:22.340 --> 05:27.970
or the next time we run the loop and then we do the action so we know something has changed.

05:28.580 --> 05:31.340
We just need to check the brain state here.

05:31.760 --> 05:34.520
If it's high, it means that we went from low to high.

05:34.520 --> 05:35.450
So we press the button.

05:35.720 --> 05:39.550
If it's low, it means we went from high to low.

05:39.560 --> 05:41.330
So the bottom was released.

05:41.750 --> 05:43.970
And now I'm going to upload that code.

05:44.870 --> 05:47.180
I'm going to save it as a button.

05:48.480 --> 05:49.140
Bounce.

05:52.140 --> 05:59.820
OK, Don, imploding and in to open the sale monitor there, and I'm going to click here on show time

05:59.820 --> 06:00.120
stamp.

06:00.180 --> 06:06.470
OK, so whenever we have something printed, we say in MONITEAU, we will also get the time stamp to

06:06.480 --> 06:11.180
help us get the exact time of the change of date.

06:11.580 --> 06:13.770
So I'm going to press the button several times.

06:14.310 --> 06:18.970
So I just press under and you can see we already have a first example of the buttons.

06:19.350 --> 06:20.360
So what did I do?

06:20.370 --> 06:28.050
I just pressed once and realized once you can see the time is really almost the same and I don't have

06:28.050 --> 06:33.840
just button pressed and button released once I have been embraced and button released twice.

06:34.350 --> 06:35.970
OK, let's make another example.

06:36.000 --> 06:36.990
So here's the mouse.

06:37.740 --> 06:38.610
I press the button.

06:38.760 --> 06:41.460
I realized I press the button.

06:41.820 --> 06:42.720
I really do it.

06:43.470 --> 06:44.160
Now let's go.

06:44.700 --> 06:47.090
Let's do a press and release quite quickly.

06:48.000 --> 06:49.140
OK, it works.

06:49.140 --> 06:50.550
We have two another one.

06:50.550 --> 06:51.870
We have to another one.

06:52.590 --> 06:53.190
Another one.

06:53.670 --> 06:54.170
Another one.

06:54.180 --> 06:58.320
Let's clear the output and let's try to get those.

07:05.020 --> 07:10.680
OK, and you can see here after several tries, so the usual behavior is that we press the button,

07:10.690 --> 07:14.770
we have been pressed, we release the button, we have button that case.

07:14.770 --> 07:22.000
You can see I press the button and then when so at this time here and then when they release the button,

07:22.510 --> 07:28.420
you can see at this exact time we also have pressed and released, which means that the Audi, you know,

07:28.420 --> 07:34.240
has detected that the button was pressed and released one more time can sometimes can be one more time,

07:34.240 --> 07:36.520
two more time, three more times, etc..

07:37.150 --> 07:42.070
So this can be quite inconvenient because let's say you want to toggle and edit, which is something

07:42.070 --> 07:43.570
we are going to do later.

07:43.570 --> 07:44.950
Also discuss.

07:45.290 --> 07:49.760
Let's say you want to toggle the algae only when you release the push-Button.

07:50.170 --> 07:54.150
So we this normal behavior, OK, you press and you release.

07:54.160 --> 07:56.120
So you are going to toggle the energy.

07:56.140 --> 08:00.220
For example, if it was put on, you pull it off.

08:00.700 --> 08:08.380
If you are going to now put it on OK with this one, you are going to pull right off and then you press

08:08.380 --> 08:09.750
again and what happens.

08:09.760 --> 08:15.060
So the end is pulled off, you press and when you release here, the energy will be pulled on.

08:15.310 --> 08:22.970
But with these two additional dates that are monitored, the energy will return to the state both.

08:23.350 --> 08:27.090
Which means that, well, that's not what you wanted to do with your program.

08:27.670 --> 08:33.400
So this is actually the bond problem that you can clearly see with this example.

08:33.640 --> 08:38.740
And what's happening here actually will in the next lesson, you will get the complete explanation.
