This is the solution of the previous activity where you have to pour the energy when the buttons pressed
and power of the ready when the button is not pressed.
So first things first.
We are going to initialize here the beams.
And before doing that, we are going to use define for being.
So this is still PIN number 11 and another defined for button.
Bean, which is number two.
OK, so for every bean you are going to use in your speech, in your program here.
Well, you can just add a define for each bean.
And then in the set up, so here we're going to use spin mode to initialize the energy in order to output
mode and in mode by the button appear.
Or input mode.
OK, so here the order is not really important, you just initialized all the feeds so you could initialize
the energy first on the button first.
It doesn't matter.
And now that the pins are set up after directly after the pin, also here in the set up for your uncle
in the loop function, we can start to rate the button state and we can start to control the the in
the loop.
What I'm going to do, I'm going to write if digital read button in.
But if this is equal to high, OK, and make sure you use to equal sine OK.
If you just use one equal sign you may have some weird arrows here.
So to equal sign, if the balloon is priced so we can read this line as if the balloon is priced, then
we are going to own the entity.
So digital.
Right, and then we've hired.
And as if the button is not pressed, we're going to do digital right in with No.
All right, and that's about it.
So now let's verify, let's combine I'm going to name it activity three.
OK, Don, combining so we don't have any Tarong and I'm going now to upload it occurred to out in the
world.
So again, make sure the board is correctly connected.
I applaud the code.
And now so you should see hear the energy.
So nothing happens.
It is pulled off.
But actually the edit is put off because we are in the end here of the if OK, because the button state
is low.
So we pull off the.
No, I'm going to press the pause button here and you can see the 3D both on OK, I release the push
button and a press error I press.
I really and every time I press, the energy would be put on and every time I release or every time
the button is, the press diary is put up.
All right.
So that's the end of this activity again with this activity.
You could have the first real example of how you can combine different hardware components.
OK, for example, with input components and output components to make a smarter program which will
take decisions depending on the status of your sensors.
And here you can see a nice combination of digital and digital right functions.