WEBVTT

00:00.330 --> 00:07.320
And before we jump into the code, what is how do to interrupt our interaction to understand interrupt?

00:07.500 --> 00:09.930
First, let's see a real life example.

00:10.710 --> 00:16.190
Let's say you are waiting for a package to arrive at your home in order to not meet the package.

00:16.200 --> 00:17.910
You have two choices of action.

00:18.450 --> 00:21.970
First, you can come back every minute to your front door to check in.

00:21.990 --> 00:24.120
The delivery truck is here or not.

00:24.450 --> 00:28.440
And that is called pulling all you can do something else.

00:28.680 --> 00:35.550
And when you hear the doorbell, you interrupt your current activity to open the front door and get

00:35.550 --> 00:36.240
the package.

00:36.660 --> 00:40.010
This is called interrupt or interruption.

00:40.590 --> 00:46.320
And when you work with a push button or a similar digital sensor, this is the same.

00:46.770 --> 00:52.800
You can either check the button state every time you get the change in the loop function or you can

00:52.800 --> 00:59.520
sit up and interrupt to post the execution of the program and call a function as soon as the button

00:59.530 --> 01:07.530
state has changed and interrupt will be triggered by hardware without necessitating the software resources

01:07.530 --> 01:08.270
of the algorithm.

01:08.760 --> 01:13.800
So when the interrupt is triggered, your program is paused and you interrupt.

01:13.800 --> 01:14.880
Function is called.

01:15.390 --> 01:20.600
As soon as your interact function has finished its execution, the program resumes.

01:21.090 --> 01:22.800
So using interrupts.

01:22.800 --> 01:25.620
This is bullying can be a good idea.

01:25.620 --> 01:32.120
For example, if you want to be notified as soon as the button is priced or released, because we've

01:32.130 --> 01:38.250
polling, even if your program goes very fast, you still have to wait for the loop function to finish

01:38.250 --> 01:45.000
out the other instructions of your application between each read of the button state, which may or

01:45.000 --> 01:47.600
may not be a problem in some situation.

01:47.850 --> 01:52.890
And also using interrupts can ensure you that you don't miss the change of the state.

01:53.460 --> 01:55.340
For the example of the package delivery.

01:55.560 --> 02:02.040
Let's say you check every minute, but then if the delivery truck comes in between that minute and just

02:02.040 --> 02:06.720
waits five seconds before leaving, well, you might miss your package.

02:07.300 --> 02:11.670
So, of course, we already know the timing is much quicker for all the action you do.

02:12.010 --> 02:14.460
OK, we are not talking in seconds or minutes.

02:14.460 --> 02:17.420
We will be talking in microseconds or milliseconds.

02:17.820 --> 02:23.510
And by using the time functionalities and not the delay functions, we pulling.

02:23.520 --> 02:27.240
You should not have the problem of missing the change of state.

02:27.750 --> 02:33.120
But the more your program grows and the more instructions you add, which can take some time, the more

02:33.120 --> 02:34.960
chance you have to miss it.

02:35.490 --> 02:42.150
So if what you want to do is to get notified of when the button state changed while also doing many

02:42.150 --> 02:45.810
other things, then using interrupts is actually a good idea.

02:46.170 --> 02:48.540
And actually just a small parenthesis here.

02:48.750 --> 02:51.380
Interrupts are not just for push buttons, ok.

02:51.900 --> 02:58.230
Interrupts can be used whenever you want to monitor the change of the state for a digital pin.

02:58.800 --> 03:02.210
Now what are the triggers for the interrupt function to be called.

03:02.670 --> 03:10.110
So here is a signal that starts low or zero vote and then goes high or five-fold, for example, when

03:10.110 --> 03:16.960
you press the button and then goes back to low when you release the button, the first mode for interrupts

03:16.980 --> 03:19.290
is rising with this mode.

03:19.470 --> 03:26.000
The interrupt will be triggered when the signal goes from low to high and only this.

03:26.400 --> 03:27.990
The second mode is following.

03:28.410 --> 03:30.150
This is the opposite here.

03:30.180 --> 03:34.280
The interrupt will be triggered when the signal goes from high to low.

03:34.950 --> 03:41.340
Then the third mode is change and is actually a combination of rising and fully.

03:42.330 --> 03:48.810
So if you have any of those two, we've changed, the incorrupt will be triggered and finally, default

03:48.810 --> 03:55.620
mode is low, this mode is a little bit different because the interrupt will be triggered whenever the

03:55.620 --> 03:56.700
signal is low.

03:57.000 --> 04:03.420
So it's quite useful when you have a signal that is high all the time and which goes to low only at

04:03.420 --> 04:07.170
some specific moments for a very short duration.

04:07.470 --> 04:10.170
But otherwise, in our case, we are not going to use it.

04:10.590 --> 04:13.700
OK, so to recap, those are the four modes you can choose.

04:13.710 --> 04:17.790
OK, we are going to see how to do that practically in the next.

04:17.790 --> 04:23.790
Listen, so we've rising to interrupt would be triggered when the signal goes from low to high.

04:24.210 --> 04:30.750
We following when the signal goes from high to low changed is the combination of rising and falling

04:31.380 --> 04:33.840
and low is whenever the signal is low.

04:34.530 --> 04:37.590
Now, what other options can you use for interrupts?

04:38.130 --> 04:43.320
Well, first, this is only happening with digital things, not analog bits.

04:43.920 --> 04:46.850
Then it depends a lot on your Arduino model.

04:47.520 --> 04:49.770
Here is a table for the most common ones.

04:50.400 --> 04:55.650
But you can see the outline of, you know, that we have or if you have the Nano or Mini, well, you

04:55.650 --> 04:58.790
only have two digital things you can use for Internet.

04:58.800 --> 05:01.230
And those are pince number two and three.

05:01.770 --> 05:03.210
OK, so only two things.

05:03.210 --> 05:08.790
If you have the Omega Omega, you can see you have much more digital things you can use for interrupts.

05:09.120 --> 05:15.570
OK, then you can see from micro Leonardo then if you have zero are doing, you can use all digital

05:15.570 --> 05:18.720
things except for the PIN number four for the Adeno Zero.

05:19.310 --> 05:25.100
OK, so you can see depending on your application, if you need to use many interrupts, well the algorithm

05:25.500 --> 05:31.980
might not be the best solution, but for what we are going to do now and for the final project of the

05:31.980 --> 05:36.070
course and for many of your project that you are going to start afterwards.

05:36.360 --> 05:37.770
The you know, is quite good.

05:37.810 --> 05:40.470
OK, you can already manage to do a lot of things.

05:40.470 --> 05:41.890
We just two interns.

05:42.210 --> 05:42.660
All right.

05:42.660 --> 05:49.360
So now you have a global understanding of what our interests are and when or why to use them.

05:49.720 --> 05:53.880
No, let's actually use interest in our program.
