WEBVTT

00:00.240 --> 00:06.930
So great, you have learned how to use interrupts and as a small parenthesis, how to use the Internet,

00:07.230 --> 00:07.680
don't know.

00:07.680 --> 00:12.480
Let's forget about these debates and let's fully focus on the interrupts themselves.

00:12.930 --> 00:14.760
So to correctly use interrupts.

00:14.940 --> 00:21.900
You have to be careful and aware about what you can and can't do and what you should and shouldn't do.

00:22.500 --> 00:27.850
Here is a quick list of the best practices and warnings that will help you when working with interests.

00:28.440 --> 00:35.130
So first, an interim function does not return any result and does not receive any parameter.

00:35.580 --> 00:41.190
So if you want to get on, modify some variables in your program, you will have to modify global variables

00:41.460 --> 00:43.290
inside the internal function.

00:43.710 --> 00:47.880
And note that for any viable you modify inside and interrupt, you should.

00:47.880 --> 00:56.010
But the volatile key word in front of the data type, when you declare the variable now inside to enter

00:56.010 --> 01:03.880
a function, you only want to write code that goes very fast to execute, for example, toggle available.

01:04.350 --> 01:06.510
Basically, that's all you should aim to do.

01:06.510 --> 01:10.550
In the interim, you should avoid doing any action in any threat.

01:11.030 --> 01:17.550
Just use the Interop to toggle available and then in your void loop function, check for that variable

01:17.550 --> 01:19.940
and execute annexion accordingly.

01:20.430 --> 01:27.300
If you stay too long inside an interrupt, you might miss important data you receive in your voice function.

01:27.540 --> 01:33.240
Or you could miss another interrupt that is deactivated while you are in the current one.

01:33.600 --> 01:39.120
Now, if you want to use time functionality inside and interrupt, be extra careful.

01:39.630 --> 01:44.160
First, the delay function won't work and delay microsurgeons.

01:44.160 --> 01:51.000
Wolk's but as you want to optimize the speed, you definitely don't want to intentionally wait in the

01:51.000 --> 01:53.750
interrupt, so don't use any of them.

01:54.180 --> 02:01.110
Something very useful can be to get the time at the beginning of you in 30 minutes and micros will give

02:01.110 --> 02:07.460
you the current time just before the entire function starts, but then inside it to interrupt function

02:07.770 --> 02:16.270
minutes will not increase and micros will work accurately about one or two milliseconds and that's it.

02:16.440 --> 02:20.460
The thing is, you don't want to spend even one millisecond on the interrupt.

02:20.850 --> 02:24.070
You just want to toggle some level and then exit.

02:24.690 --> 02:30.880
So just use Milice on micros to get the time at the beginning if you need it, but no more.

02:31.470 --> 02:34.440
And finally, simple doesn't work in the Interent.

02:34.950 --> 02:40.020
If you want to bring something when an interrupt was triggered, you will have to do it in the void

02:40.020 --> 02:46.710
loop function and find a way to notify the loop when to interrupt was triggered to conclude.

02:46.710 --> 02:53.190
You can see that there are many drawbacks and limitations about interrupt interrupt a powerful Ardino

02:53.310 --> 02:53.880
function.

02:54.090 --> 02:58.950
But to use with care, with the information you have here, you should be fine.

02:59.280 --> 03:05.550
And because all those limitations and things to care about, it's best to use interrupt only when you

03:05.550 --> 03:09.220
really need them when designing a new project.

03:09.360 --> 03:14.130
Always ask yourself if what you want to achieve can just be done with pulling.

03:14.620 --> 03:16.760
If yes, then use pulling.

03:16.950 --> 03:23.220
If, however, you might miss some data using, pulling or get information a little bit too late, then

03:23.370 --> 03:24.600
go with interrupts.
