And before we jump into the code, what is how do to interrupt our interaction to understand interrupt?
First, let's see a real life example.
Let's say you are waiting for a package to arrive at your home in order to not meet the package.
You have two choices of action.
First, you can come back every minute to your front door to check in.
The delivery truck is here or not.
And that is called pulling all you can do something else.
And when you hear the doorbell, you interrupt your current activity to open the front door and get
the package.
This is called interrupt or interruption.
And when you work with a push button or a similar digital sensor, this is the same.
You can either check the button state every time you get the change in the loop function or you can
sit up and interrupt to post the execution of the program and call a function as soon as the button
state has changed and interrupt will be triggered by hardware without necessitating the software resources
of the algorithm.
So when the interrupt is triggered, your program is paused and you interrupt.
Function is called.
As soon as your interact function has finished its execution, the program resumes.
So using interrupts.
This is bullying can be a good idea.
For example, if you want to be notified as soon as the button is priced or released, because we've
polling, even if your program goes very fast, you still have to wait for the loop function to finish
out the other instructions of your application between each read of the button state, which may or
may not be a problem in some situation.
And also using interrupts can ensure you that you don't miss the change of the state.
For the example of the package delivery.
Let's say you check every minute, but then if the delivery truck comes in between that minute and just
waits five seconds before leaving, well, you might miss your package.
So, of course, we already know the timing is much quicker for all the action you do.
OK, we are not talking in seconds or minutes.
We will be talking in microseconds or milliseconds.
And by using the time functionalities and not the delay functions, we pulling.
You should not have the problem of missing the change of state.
But the more your program grows and the more instructions you add, which can take some time, the more
chance you have to miss it.
So if what you want to do is to get notified of when the button state changed while also doing many
other things, then using interrupts is actually a good idea.
And actually just a small parenthesis here.
Interrupts are not just for push buttons, ok.
Interrupts can be used whenever you want to monitor the change of the state for a digital pin.
Now what are the triggers for the interrupt function to be called.
So here is a signal that starts low or zero vote and then goes high or five-fold, for example, when
you press the button and then goes back to low when you release the button, the first mode for interrupts
is rising with this mode.
The interrupt will be triggered when the signal goes from low to high and only this.
The second mode is following.
This is the opposite here.
The interrupt will be triggered when the signal goes from high to low.
Then the third mode is change and is actually a combination of rising and fully.
So if you have any of those two, we've changed, the incorrupt will be triggered and finally, default
mode is low, this mode is a little bit different because the interrupt will be triggered whenever the
signal is low.
So it's quite useful when you have a signal that is high all the time and which goes to low only at
some specific moments for a very short duration.
But otherwise, in our case, we are not going to use it.
OK, so to recap, those are the four modes you can choose.
OK, we are going to see how to do that practically in the next.
Listen, so we've rising to interrupt would be triggered when the signal goes from low to high.
We following when the signal goes from high to low changed is the combination of rising and falling
and low is whenever the signal is low.
Now, what other options can you use for interrupts?
Well, first, this is only happening with digital things, not analog bits.
Then it depends a lot on your Arduino model.
Here is a table for the most common ones.
But you can see the outline of, you know, that we have or if you have the Nano or Mini, well, you
only have two digital things you can use for Internet.
And those are pince number two and three.
OK, so only two things.
If you have the Omega Omega, you can see you have much more digital things you can use for interrupts.
OK, then you can see from micro Leonardo then if you have zero are doing, you can use all digital
things except for the PIN number four for the Adeno Zero.
OK, so you can see depending on your application, if you need to use many interrupts, well the algorithm
might not be the best solution, but for what we are going to do now and for the final project of the
course and for many of your project that you are going to start afterwards.
The you know, is quite good.
OK, you can already manage to do a lot of things.
We just two interns.
All right.
So now you have a global understanding of what our interests are and when or why to use them.
No, let's actually use interest in our program.