This is the solution to the previous activity where you need to print an increasing content on the sale
whenever you press the button using, of course, entrance.
So let's first write the code for the Internet.
OK, look for the Internet.
We need the button beam.
So the final button beam, which is number two in the set up, I'm going to do in mode button in with
input and I'm going to create an interactive function.
So void.
OK, no other data type.
Button pressed into it.
And no parameter, right, so I have my interpretation that I'm going to feel just a little bit later,
you know, what I'm going to do is attach.
Digital 18 to.
Interact with the button.
OK, then go back to a new line, let's align the parameters, just which more reasonable, I'm going
to put the name of the function button pressed.
Interrupts And then I'm going to put the mode which is rising to rising when the signal goes from low
to high.
In other words, we will up when we pressed the perfectly.
All right.
And I'm going to do almost the exact same thing as I did in the previous lessons is I'm going to add
fly here.
Bill Burton is false and set the flag, as Britain pressed is true, and of course, I'm going to do
also the debates just after.
But this is the principle.
I create a flight so I can initialize it to polls and then I set it to true inside.
Interrupts, of course, all the time.
And then in the loop function, I'm just going to try to structure if.
Button pressed.
But we are going to say Britain is not full, so we don't enter this if again and again and again we
are going to enter this, if only the next time that it wasn't expressed.
The after I have done that, I can do the action.
I want to do it and I'm going to do after.
I know.
Let's come back to the button to interrupt.
I'm going to denounce the button and signed long last time.
But right, which is Moelis and unsigned long.
Diebold's.
DeLay, let's put 50 milliseconds, hey, and I'm going to get the times and saying long time no these
minutes don't know, you should be pretty familiar with this.
OK, this should be OK for you.
Time now, minus last time we pressed the button.
So this is a duration, if this duration is greater than the DBMS delay, then yes.
We can do our action and we are also going to update the last time the button was pressed to time now,
and if we update these viable, we need to set it as.
Look, dial.
All right, so now here we know that.
We have pressed the button and so I can put this in the.
OK, and the interrupt plus the demands now is good, so what we can do now is to do the action inside
the look.
So what do we need to do?
We need to increase a counter and print that content.
So that's actually pretty simple.
Let's create a counter here.
Let's create a global viral it conter that's initialize it to zero.
And here, let's do counter placeless, so every time we press the button, it's going to go into interrupt.
We said the flag here to true in the loop, we continuously check for this flag, if this flag is true,
then we enter this or we set it to false and then we do the action.
So every time we press the button, in the end, the content will be incremented by one and then say,
oh, that brings so Zao here.
That again.
Of course.
If we want to use the same, don't forget Salian and sell that.
Bring it let's bring some nice text, OK?
Conter is.
These and then say all that, and then we've come to.
All right, just like this.
And now it seems to be good, so I can.
Verified good.
Activity.
Don compelling me to upload the code.
Don't imploding and let's open the sale monitor and I'm going to press the button so I press it is what
I release the push button.
Nothing happens.
I press it again, control to I release nothing until three, four, five, six, etc..
So here you can clearly see that in the loop, our code is pretty simple, OK, and the action to monitor
when we pressed the button is outside of the main program.
OK, and is happening with the interrupt, and that's the end of the section with interrupts.
We are actually going to come back to this later on in schools with a different example and we have
a different hardware component.