So let us go back here to this example that we were studying regarding how to control the several major.
And let us see, how can we incorporate our interrupt?
Instead of having this ball every time we need to change the about this ball right here is really slow,
it requires you to check for a button in every iteration.
And in our case here, we have 180 checks.
And this way it's a lot of time for all the while loop.
So let us get started by and see how we can handle it.
So the first thing we want to do is I want to change the wiring right here.
So we have only been number two and three are responsible for interrupting all the other bits.
It's not so easy to use interrupts on that.
So here's what we're going to do.
First, let me define a pin that will be used for my interrupt.
I'm going to call that integer.
Enter just like this, and it's going to equal to two.
OK, so interrupt will be on this PIN number to know.
How can I incorporate this in the configuration, how can I add this into the configuration?
First, you need to configure a pin number two as input.
So it's just a very simple input pull up.
So just copy paste here and just say the enter is actually an input pull up.
OK, no.
Next, what we're going to do is we need to configure the interact.
In order to do that, you need to call a function called attach interop.
So this is at that.
Interrupt.
You would simply give the name of the interrupt here, which is enter and next.
You need to specify which function you're going to use.
Now I'm going to show you the reference for how to use it.
You just need to go to Adreno and type interrupt.
And go to the Dutch Interop function and here you go.
This is all the information you need to know about it now.
Now, let me take a look at the function.
This is my function.
It's recommended that I use digital pen to interrupt function at my pen.
They're saying that please use this formula right here in order to in order to attach and interrupt.
So let us copy this.
Go back here and just say.
Digital pen to interrupt and then they enter.
OK, we'll do we'll go with the original site recommendation.
Next we have the Isaw.
Now there is or is the routine that we are going to jump to.
In our case, every time we push a button, we want to jump to this routine to get a button, I want
to see whenever I activate and interrupt, I want to know which button was pressed.
Right.
So I'm going to just copy the name of my function and I'm going to put it here.
So PIN number the function and then when should this be considered?
When should I exactly activate that routine?
Well, this is what Moutier talks about.
So if I go to mode, mode has low change, rising, falling low whenever I press my button and it is
at the low point and meaning that I am sending zero volts to my interrupt, then all the time my routine
will be activated and I'm going to jump directly to the Gates button whenever my interrupt is at low.
Another thing is I can put it on change.
So let's say my interrupt was high, then I press the button, it goes low and then the then the interrupts
will be activated.
Now if I release and it goes back to high or five volt, well, I will activate it again.
So every transition between high and low, I'm going to be able to trigger my interrupt routine accordingly.
Now I have rising and falling.
We've talked about rising and falling just a lot, actually, when we were in the video section.
So rising, I mean, we are going from low to high.
Just that instance that is going from low to high, that's going to trigger my protein folding is the
opposite way.
When I am at high, then I am dropping to low.
So this changing in voltages is considering the voltage attach, the voltage applied on the interruption,
and in our case it is the voltage applied at number NO2.
So is it the low voltage?
Is it rising?
Is it the falling?
Depending on the status, I'm going to be able to do that depending on the status.
I'm going to trigger my routine right here.
So in my case, when I press the button, I am changing it from high to low.
Right.
So this is a falling edge because, well, all my buttons are connected to pull up.
So it's always hireling it it goes low, so it's from high to low.
So I need the falling mode.
So I'm going to type here falling.
OK, I could type slow change, rising, falling, whatever I want, depending on the mode I want to
use.
And that's it.
This is how I touch my interrupt.
No.
There is something you need to know about the interrupt function.
Now, this is my interrupt function, right?
Interrupt the function should not return anything.
So when you say integer here, this will give you a compilation error immediately.
Now, let me clean my loop for a moment.
Just for a second.
I will try to compile my code.
I'm going to show you the error.
I'm going to get see this invalid conversion from integer to avoid because this is because I am specifying
that this is my interrupt routine.
I'm specifying it right here.
Right.
So this is integer and integer.
Always expect to return something.
It could return an integer.
So that's wrong.
Float is wrong.
Boolean is wrong.
It could only be void.
The void is something that does not return any value.
So you cannot even use the return here in order to do that.
So what should we replace return with?
Well, we could set the button variable directly.
How about that.
So I could say here button.
Equals one, I'm not returning anything using my function.
All I'm doing is I'm setting up a global value, different value.
So when I press a button, this will be triggered, it's going to see OK, but one is a press, it will
set this valuable right here and it's going to exit the interrupt routine and that's it.
So all I need to do here, instead of using return, I'm going to just set a valuable I'm going to do
this for all the cases.
And I don't even need else if none of the buttons is pressed, I just want to keep my button here at
whatever status it is.
That's it.
This is all I need to do.
Well, this is regarding my routine.
I'm going to return everything that I have deleted it from here.
And here we go, let us start adapting our loot in order to make it work with the new modifications.
So right now, I don't really need to go and check myself if there is a button pressed.
Right, because I just activated the trigger.
Whenever a button is triggered, it will automatically exit this function and execute this one.
I don't need to define anything else regarding calling which button is being pressed.
I already done that right here at the trigger section.
So another thing I need to do, I don't need this check anymore.
Remember Inside the loop were checking.
Everybody's oppressed.
I don't need to do that anymore.
What I need to do is let's say that I leave everything as it is.
I suppose it it could be held.
We could think we might think that we are ready and we could go.
Let us try simulating.
OK, now let me stop for a minute right here, let's suppose that I am done with the coat, supposedly
I have reactivated my my interrupt.
I have deleted here so I could expect that whenever I am inside this lobe and I press the button, the
button is going to change.
And by that I'm going to adjust the speed.
But that's the point.
I did not adjust the speed yet.
Is that correct?
Because, well, even though let's say I am inside here and delete and I have changed my button, delay
time did not change yet because I did not even call speed option.
So how are we going to do that?
Well, I'm going to cut this whole line right here and I'm going to put it in my team.
So after I am done checking all the conditions, I just want to set delay time.
Remember, DeLay time will specify the exact rotational speed, the exact delay which will set the exact
speed for my motor.
Right.
So let's say that button is one.
We're done with all the conditions.
Now we can jump to this statement and set the correct speed.
Now, you might ask, isn't this attached to this else?
If no, if I want to make it attach to this or else if I need to do it in a curly brackets like that.
But if I don't have it in a curly bracket, I'm going to execute the if one wants this, if executed,
I'm going to cut I'm going to jump over all of this and I'm going to jump to the next instruction that
has nothing to do with if and by that, whenever I press a button, I'm going to set the button.
I'm going to set the speed at the same time.
OK, and that's it.
Now we're going to debug and see if this will work.
But first, we did not do anything with the hardware.
Let us do some stuff with the hardware.
Remember that.
We need to use that, you know, get that diet.
But you need to make sure that the line here is rotated so precise.
Or if you press all, you are going to be rotating by pressing or.
OK, let's play the first diode here.
We got it by our second one, get another one.
Go by our.
Get the third one and rotate by, or you can search for a diode by just typing diode like that.
OK, next, do you remember our diagram?
Our diagram suggests that I connect all of these terminals together and just connect them to the interrupt.
Right.
Remember?
So all I need to do is I'm going to connect all of these.
Together to this joint point.
Make sure you're connecting all of them to the joint one by one.
Don't try to do to drag and drop between the two points between two, four or eight points.
This will not interconnect the middle points, so just connect them one by one and the next we need
to connect or every everyone.
We need to connect every button with the other terminal.
Here.
And here.
This is exactly this is exactly like this topology, as you can see, all the dots are linked at one
point they are connected to the interrupt and then the other side of the dirt is connected to the first
side of the switch.
OK, now how about we just add one more line here, which is it's going to print to me which button
is being set right now.
OK, so let's go to set up and let us call Circle Begin in order to initiate our serial 9600 boat.
And now inside my routine here, I just want to print my so I'm going to say serial dot print l.n..
I just want to print button in order to know which button is being pressed right now.
Now let us head on simulation and see what's going to happen.
We have another.
Well, here's the thing, whenever you want to define and interrupt, Ben, you need to define is as
constant.
OK, so let us start simulation.
All right, so it's still complaining about in void, it looks like we forgot to change this to avoid
maybe I pressed controls it at some point and this was deleted.
Let me try again.
So it's void right now.
It's not returning anything.
OK.
Now, let us simulate.
Nothing is happening.
Oh, OK, we've got to connect this to the interrupt.
Sorry about that.
Let's take a wire from here and just connect it to Tombouctou and let us start simulation.
Now, that's up in our code.
If I press the first button, as you can see, button now, value is one and it's rotating really slowly
if I press the fast one.
Nothing is happening.
Why is that?
Well, because we also have another wiring issue is that we did not connect this last speed.
OK, so let me check it again.
Double check, everything connected, all four or connected or full.
I connected.
And here it's connected as well.
Now, let us try again, quote, clear speed, number one.