micropython
micropython copied to clipboard
Button pins and read_digital
I was researching something regarding microbit pins. I found an up coming feature that button pins (5 & 11) were reusable as read_digital pins.
It may be the case, i didn't read all the source.
Once pinX.set_pull
or pinX.read_digital
has run on pin 5/11 then it should now throw an exception if button_a
or button_b
methods such as .is_pressed()
is used.
Hi @rhubarbdog,
I want to make sure I understood this part correctly:
Once pinX.set_pull or pinX.read_digital has run on pin 5/11 then it should now throw an exception if button_a or button_b methods such as .is_pressed() is used.
Do you mean that once the pull up/down method is used on the button pins, then using the button_a/b methods should raise exceptions?
Yes. Otherwise users will think they can connect external components to pin5/ pin11 and use buttons. If the program is in # read component
pressing the button will cause glitches and accessing button_a.get_presses()
after a component has buzzed pin5 will yeild an unexpected result.
A user may want to use both the button and input pin (5/11) on the edge connector at the same time, so I think the code should allow such flexibility. Using the button pins as digital inputs isan advanced feature, so users should in such a case be aware that advanced usage can lead to unexpected behaviour (which may actually be expected if the user knows what they are doing and wants it to behave this way).
If anything, this would just need a note in the docs, rather than an addition to the code to restrict usage.
The docs mention the pull up resistors in https://microbit-micropython.readthedocs.io/en/latest/pin.html , what can of note can we add to the docs to make the digital read behaviour more clear?
Add the text.
This implies that pins 5 and 11 are only usable as read_digital pins. Testing for if pin5.read_digital() == 0: