So let me talk to you about injuries we have seen already, the challenge and the waste of time we would
had to do in order to scan if a button was pressed, we had to incorporate checking if a button is pressed
inside our lube.
And that was really a waste of time because, well, we are wasting a lot of cycles inside of those
four loops in order just to check if a button was pressed.
That's not really practical at all.
Imagine if you have a much larger program with too many loops that are going and taking place.
It just does not make any sense that I should check for my button in every single loop or in every in
the places in my code.
That's really a burden right here.
This is why we are going to incorporate that.
We're going to learn about rates.
So let us recap again, assume this is my main program running and I have 20 actions.
Some of them are lubes, some of them are in normal instructions.
And let's say I want to read a button exactly like this, Inagua, we had, if I am inside action too,
which could be a for loop that is counting, let's say, between zero and 10000.
So let's say I am in action.
Do I am inside the loop that is counting between zero and 10000.
And let's say I have some action that requires me if I press a button, some whole scenario is supposed
to change, then I cannot do it because I'm stuck in the loop and the button update is way down there.
So no matter how many times I press, I won't be able to recognize this button because I'm stuck in
some different portion of the code.
This is where Interrupts comes into place.
Now, simply interrupt you just configure it in your set up.
You say, OK, I just want to configure that.
I'm going to use and interrupt at some at a certain point in our case, we can use PIN number two and
three on Audrina.
Oh, no, no.
Whenever I press this button, it doesn't matter where I am inside my loop.
I'm going to break out of this loop.
All of it.
No matter how many folks are inside, no matter where I am right now, I'm just going to break out of
here and I'm going to jump to a subroutine or an interrupt your team that can execute whatever I want.
So let's say that I configure that button to it's supposed to be an interrupt base cell.
And here we are executing some instructions.
I press this button, I break out of here and I go execute something in this other subroutine or this
other function.
This function could be scanning which button is pressed, OK?
Or it could be doing any other action that is outside of this loop.
So in our case, as I said, it could be that, OK, I just want to notify my board that some button
was pressed and I wanna just figure out what was oppressed.
So I break out of here, whatever it's doing, I check my button, I change some valuables up there,
update some valuables.
Let's say I update the button that was pressed.
And then after this function is done executing, I go back to exactly where I was in my loop.
Let's say I was inside a for loop.
I broke out of it.
This does not mean a full of breaking out of the loop.
This is just a temporarily break.
I break out of this for loop that is inside my void loop here.
I break out of it, I execute something and I go back here, let's say it's counting between zero and
ten thousand.
And it was at count five.
I count five, execute something, go back exactly as count five and just continue as nothing has happened.
This is why interrupts are amazing.
So it ignores everything in this routine and just executes something else.
Now let me recap for you.
You press a button, we break out of the loop, we execute whatever we have here, and then we go back
exactly where we were left at.
You know, the next lecture.
We're going to see how we can implement this interrupt.