In this lecture, you have to read the state of the commentary button.
I'm going to show you how to do that, using three different examples each time to bring a different
capability of the ECB through in macro python to achieve the same thing.
But each time with a bit more efficiency across the three examples, the hardware is not going to change
in all cases.
Have the ECB three to have a momentary pattern.
She can see that is connected to Jebril for this pin right here.
And I am using the ECB 32 internal pull up so that I don't need to use an additional wire to bring up
the unpressed state of the button to high would use the internal pull up register for that.
And I also have a wire here that will bring the state of the button to know when it's pressed.
So that's what will be detecting to show, in effect of the button press I've got in here, just like
in the previous lectures that is connected to Tapio 21 and that's about it with a hardware.
In the first example that I'll show you in this lecture, I am reading the state of the button in the
simplest possible way by using an infinite loop here.
So I'm using the while loop than a passing true as its permanent state so that the program is going
to be locked inside this block.
So constantly it will be using this instruction to read the value of the button and if it is low represented
by zero here.
So logical state is low because you can see that the pressed state of the button is pushed down to zero
volts, then will turn the old on and will stay there for ten milliseconds.
And if the state of the button is not zero, it's one because of the internal pull up then will turn
the ability of a couple of other things in this sketch worth talking about, I have used this expression
here to declare the object of the button and you can see that I'm using the PIN constructor, just like
I did with a PIN constructor for the ality here.
But in this case, I've got three arguments.
The first one is the GPO.
The second one indicates that this is going to be an input and then the third one activates the internal
pull up front.
To learn more about the PIN constructor, have a look at this link here, which will take you to this
page in the quick reference for the HB three two or the Micro Python website.
And it shows you an example of how to use these functions.
And again, if you want even more information than good to have a look at the machine Dot Pincott,
which is this page right here.
This is it.
And you can see the constructors in my example.
I'm using this constructor here to create an object for idea of the Tapio number for in our case then
for mode, I'm using Penkin as opposed to pin down for the elite.
This opinion is for the button.
And then we also have the polyposis, stuff like that.
So Pincott pull up is a way to turn on the pull up resistor you can see.
And like the other, you know, you can also have the pull down resistor if you use Pendo, pull down
and that's about it.
The rest can be immediate and they will just take the default values.
Another new thing that I'm using here is the tick and the call and this function.
You can see that I'm using that down here.
I'm importing it from you time.
So from Micro Python version of the time, I see Python module.
So this function here, you can get more information about it right there.
It gives us the number of milliseconds since we have power to up the speed.
Three, two.
And that's because we want to see information about the moment that I pressed on the button and I'm
bringing out the number of milliseconds since the activity was powered up when I pressed the button
right here.
OK, let's try this out.
So at the moment, I've noted the script from my computer disk and my computer file system.
So what I do is to save a copy with the macro python device in the name will be Button and it's call
for the API.
All right, here it is and double click on it to bring it up, you know, close the window that contains
the version of the script on the computer file system.
You know that I've got the script selected on the E.S.P 32.
I will play it.
All right, to press the button, you it is one text comes through to the show of my Thony Editor Button
pressed, and then the number of seconds when the button pressed, it's been detected.
All right.
Obviously, this is not a very efficient way, again, to use the hardware.
So I want to show you two additional methods of the set of a button that do not involve using a wire,
at least not to do the reading.
So let's have a look at the next lecture where I'll show you how to do the exact same thing more efficiently
using a hardware interactive.