WEBVTT

00:00.180 --> 00:06.950
This is the solution to the previous activity where you need to print an increasing content on the sale

00:07.410 --> 00:11.340
whenever you press the button using, of course, entrance.

00:11.700 --> 00:14.350
So let's first write the code for the Internet.

00:14.400 --> 00:16.110
OK, look for the Internet.

00:16.170 --> 00:17.590
We need the button beam.

00:17.610 --> 00:29.550
So the final button beam, which is number two in the set up, I'm going to do in mode button in with

00:30.360 --> 00:34.590
input and I'm going to create an interactive function.

00:35.220 --> 00:36.180
So void.

00:36.270 --> 00:38.700
OK, no other data type.

00:40.160 --> 00:43.390
Button pressed into it.

00:44.590 --> 00:52.860
And no parameter, right, so I have my interpretation that I'm going to feel just a little bit later,

00:52.860 --> 00:54.940
you know, what I'm going to do is attach.

00:59.270 --> 01:01.640
Digital 18 to.

01:03.150 --> 01:05.000
Interact with the button.

01:07.110 --> 01:14.670
OK, then go back to a new line, let's align the parameters, just which more reasonable, I'm going

01:14.670 --> 01:17.710
to put the name of the function button pressed.

01:19.060 --> 01:26.950
Interrupts And then I'm going to put the mode which is rising to rising when the signal goes from low

01:26.950 --> 01:27.590
to high.

01:28.330 --> 01:32.140
In other words, we will up when we pressed the perfectly.

01:32.740 --> 01:33.180
All right.

01:33.190 --> 01:39.450
And I'm going to do almost the exact same thing as I did in the previous lessons is I'm going to add

01:39.460 --> 01:40.270
fly here.

01:42.240 --> 01:53.140
Bill Burton is false and set the flag, as Britain pressed is true, and of course, I'm going to do

01:53.160 --> 01:54.720
also the debates just after.

01:55.030 --> 01:56.520
But this is the principle.

01:56.910 --> 02:01.870
I create a flight so I can initialize it to polls and then I set it to true inside.

02:01.950 --> 02:04.440
Interrupts, of course, all the time.

02:05.730 --> 02:10.230
And then in the loop function, I'm just going to try to structure if.

02:11.470 --> 02:12.970
Button pressed.

02:14.490 --> 02:22.590
But we are going to say Britain is not full, so we don't enter this if again and again and again we

02:22.590 --> 02:25.700
are going to enter this, if only the next time that it wasn't expressed.

02:25.980 --> 02:29.460
The after I have done that, I can do the action.

02:29.460 --> 02:32.870
I want to do it and I'm going to do after.

02:33.270 --> 02:33.600
I know.

02:33.630 --> 02:37.140
Let's come back to the button to interrupt.

02:37.140 --> 02:43.650
I'm going to denounce the button and signed long last time.

02:44.700 --> 02:51.180
But right, which is Moelis and unsigned long.

02:53.040 --> 02:53.680
Diebold's.

02:55.280 --> 03:05.520
DeLay, let's put 50 milliseconds, hey, and I'm going to get the times and saying long time no these

03:05.840 --> 03:09.420
minutes don't know, you should be pretty familiar with this.

03:09.440 --> 03:11.080
OK, this should be OK for you.

03:12.050 --> 03:16.040
Time now, minus last time we pressed the button.

03:17.500 --> 03:24.220
So this is a duration, if this duration is greater than the DBMS delay, then yes.

03:25.460 --> 03:35.240
We can do our action and we are also going to update the last time the button was pressed to time now,

03:36.290 --> 03:40.840
and if we update these viable, we need to set it as.

03:42.170 --> 03:43.060
Look, dial.

03:44.780 --> 03:47.990
All right, so now here we know that.

03:49.520 --> 03:54.320
We have pressed the button and so I can put this in the.

03:58.390 --> 04:05.840
OK, and the interrupt plus the demands now is good, so what we can do now is to do the action inside

04:05.840 --> 04:06.250
the look.

04:06.280 --> 04:07.610
So what do we need to do?

04:08.080 --> 04:11.640
We need to increase a counter and print that content.

04:12.220 --> 04:13.890
So that's actually pretty simple.

04:14.410 --> 04:15.880
Let's create a counter here.

04:16.340 --> 04:22.480
Let's create a global viral it conter that's initialize it to zero.

04:25.750 --> 04:34.720
And here, let's do counter placeless, so every time we press the button, it's going to go into interrupt.

04:35.940 --> 04:42.150
We said the flag here to true in the loop, we continuously check for this flag, if this flag is true,

04:42.630 --> 04:46.900
then we enter this or we set it to false and then we do the action.

04:46.930 --> 04:53.250
So every time we press the button, in the end, the content will be incremented by one and then say,

04:53.250 --> 04:55.980
oh, that brings so Zao here.

04:56.490 --> 04:57.750
That again.

04:57.750 --> 04:58.290
Of course.

05:00.360 --> 05:05.150
If we want to use the same, don't forget Salian and sell that.

05:06.570 --> 05:09.290
Bring it let's bring some nice text, OK?

05:11.110 --> 05:12.460
Conter is.

05:13.770 --> 05:18.560
These and then say all that, and then we've come to.

05:19.770 --> 05:21.240
All right, just like this.

05:24.210 --> 05:27.720
And now it seems to be good, so I can.

05:29.600 --> 05:30.480
Verified good.

05:32.190 --> 05:33.030
Activity.

05:37.120 --> 05:39.700
Don compelling me to upload the code.

05:41.240 --> 05:48.710
Don't imploding and let's open the sale monitor and I'm going to press the button so I press it is what

05:48.740 --> 05:50.050
I release the push button.

05:50.060 --> 05:51.080
Nothing happens.

05:51.470 --> 06:00.550
I press it again, control to I release nothing until three, four, five, six, etc..

06:01.890 --> 06:08.910
So here you can clearly see that in the loop, our code is pretty simple, OK, and the action to monitor

06:08.910 --> 06:13.300
when we pressed the button is outside of the main program.

06:13.320 --> 06:19.280
OK, and is happening with the interrupt, and that's the end of the section with interrupts.

06:19.410 --> 06:25.650
We are actually going to come back to this later on in schools with a different example and we have

06:25.650 --> 06:27.270
a different hardware component.
