Skip to content

Commit

Permalink
Add was_touched
Browse files Browse the repository at this point in the history
I think the docs PRs are missing get_touches too but will revisit that.
  • Loading branch information
microbit-matt-hillsdon committed Mar 19, 2024
1 parent daa5d2c commit 791689a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lang/en/typeshed/stdlib/microbit/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,19 @@ class MicroBitTouchPin(MicroBitAnalogDigitalPin):
Example: ``pin0.is_touched()``
The default touch mode for the pins on the edge connector is ``resistive``.
The default for the logo pin **V2** is ``capacitive``.
:return: ``True`` if the pin is being touched with a finger, otherwise return ``False``.
"""
...

**Resistive touch**
This test is done by measuring how much resistance there is between the
pin and ground. A low resistance gives a reading of ``True``. To get
a reliable reading using a finger you may need to touch the ground pin
with another part of your body, for example your other hand.
def was_touched(self) -> bool:
"""Check if the pin was touched since the last time this method was called.
**Capacitive touch**
This test is done by interacting with the electric field of a capacitor
using a finger as a conductor. `Capacitive touch
<https://www.allaboutcircuits.com/technical-articles/introduction-to-capacitive-touch-sensing>`_
does not require you to make a ground connection as part of a circuit.
Example: ``pin0.was_touched()``
:return: ``True`` if the pin is being touched with a finger, otherwise return ``False``.
:return: ``True`` or ``False`` to indicate if the pin was touched since the device started or since the last time this method was called.
"""
...

def set_touch_mode(self, value: int) -> None:
"""Set the touch mode for the pin.
Expand All @@ -304,6 +299,18 @@ class MicroBitTouchPin(MicroBitAnalogDigitalPin):
The default touch mode for the pins on the edge connector is
``resistive``. The default for the logo pin **V2** is ``capacitive``.
**Resistive touch**
This test is done by measuring how much resistance there is between the
pin and ground. A low resistance gives a reading of ``True``. To get
a reliable reading using a finger you may need to touch the ground pin
with another part of your body, for example your other hand.
**Capacitive touch**
This test is done by interacting with the electric field of a capacitor
using a finger as a conductor. `Capacitive touch
<https://www.allaboutcircuits.com/technical-articles/introduction-to-capacitive-touch-sensing>`_
does not require you to make a ground connection as part of a circuit.
:param value: ``CAPACITIVE`` or ``RESISTIVE`` from the relevant pin.
"""
...
Expand Down

0 comments on commit 791689a

Please sign in to comment.