From ae76850d5978f6ce7dfb8c6eae5c8c0993e7f700 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Mon, 4 Mar 2024 16:57:33 +0000 Subject: [PATCH 1/3] docs: Move resistive/capacitive description to set_touch_mode(). --- docs/pin.rst | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/pin.rst b/docs/pin.rst index 3cf539d0d..635b2015f 100644 --- a/docs/pin.rst +++ b/docs/pin.rst @@ -202,10 +202,15 @@ its own to that. Return ``True`` if the pin is being touched with a finger, otherwise return ``False``. + .. py:method:: set_touch_mode(value) + .. note:: - The default touch mode for the pins on the edge connector is + The default touch mode for the pins on the edge connector is `resistive`. The default for the logo pin **V2** is `capacitive`. + Set the touch mode for the given pin. Value can be either ``CAPACITIVE`` + or ``RESISTIVE``. For example, ``pin0.set_touch_mode(pin0.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 @@ -218,15 +223,6 @@ its own to that. `_ does not require you to make a ground connection as part of a circuit. - .. py:method:: set_touch_mode(value) - - .. note:: - The default touch mode for the pins on the edge connector is - `resistive`. The default for the logo pin **V2** is `capacitive`. - - Set the touch mode for the given pin. Value can be either ``CAPACITIVE`` - or ``RESISTIVE``. For example, ``pin0.set_touch_mode(pin0.CAPACITIVE)``. - The pull mode for a pin is automatically configured when the pin changes to an input mode. Input modes are when you call ``read_analog`` / ``read_digital`` / ``is_touched``. The default pull mode for these is, respectively, ``NO_PULL``, From 67fd7c718210a6e1a20766b070600bcfd47e0d3e Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Tue, 19 Mar 2024 19:05:07 +0000 Subject: [PATCH 2/3] docs: Add was_touched() & get_touches() for pins 0, 1, 2, pin_logo. --- docs/microbit_micropython_api.rst | 19 +++++++++++++++---- docs/pin.rst | 10 ++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/microbit_micropython_api.rst b/docs/microbit_micropython_api.rst index 19362fdac..c2fff60f9 100644 --- a/docs/microbit_micropython_api.rst +++ b/docs/microbit_micropython_api.rst @@ -149,18 +149,29 @@ Each of these pins are instances of the ``MicroBitPin`` class, which offers the # Only available for touch pins 0, 1, and 2. Returns boolean if the pin # is touched pin.is_touched() - # Only available for touch pins 0, 1, 2 and on micro:bit V2 also the logo. - # Sets the touch mode. Value can be either RESISTIVE or CAPACITIVE + # Only available for touch pins 0, 1, and 2. Returns boolean if the pin + # has been touched since the last time this method was called + pin.was_touched() + # Only available for touch pins 0, 1, and 2. Returns the running total of + # pin touches, and resets this counter to zero + pin.get_touches() + # Only available for touch pins 0, 1, and 2. Sets the touch mode. + # Value can be either RESISTIVE or CAPACITIVE pin.set_touch_mode(value) Except in the case of the pins marked **V2**, which offers the following API: pin_logo:: - # returns boolean for logo touch pin + # returns a boolean for logo touch pin pin_logo.is_touched() + # returns a boolean if the logo was pressed since the last time + # this method was called + pin_logo.was_touched() + # returns the running total of touches, and resets this counter to zero + pin_logo.get_touches() # Sets the touch mode. Value can be either RESISTIVE or CAPACITIVE - pin.set_touch_mode(value) + pin_logo.set_touch_mode(value) pin_speaker, as the above ``MicroBitPin`` class, but does not include ``pin.is_touched()``. diff --git a/docs/pin.rst b/docs/pin.rst index 635b2015f..82b4e88dd 100644 --- a/docs/pin.rst +++ b/docs/pin.rst @@ -202,6 +202,16 @@ its own to that. Return ``True`` if the pin is being touched with a finger, otherwise return ``False``. + .. py:method:: was_touched() + + Returns ``True`` or ``False`` to indicate if the pin was touched + since the device started or since the last time this method was called. + + .. py:method:: get_touches() + + Returns the number of times the pin was touched + since the device started or since the last time this method was called. + .. py:method:: set_touch_mode(value) .. note:: From b2a0dc994fa5965befe7835cba0f6556a058a2c1 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Mon, 16 Sep 2024 17:55:51 +0100 Subject: [PATCH 3/3] docs: Add touch_calibrate() for pins 0,1,2, logo. --- docs/microbit_micropython_api.rst | 5 +++++ docs/pin.rst | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/docs/microbit_micropython_api.rst b/docs/microbit_micropython_api.rst index c2fff60f9..228dc1fd7 100644 --- a/docs/microbit_micropython_api.rst +++ b/docs/microbit_micropython_api.rst @@ -158,6 +158,9 @@ Each of these pins are instances of the ``MicroBitPin`` class, which offers the # Only available for touch pins 0, 1, and 2. Sets the touch mode. # Value can be either RESISTIVE or CAPACITIVE pin.set_touch_mode(value) + # Only available for touch pins 0, 1, and 2. Re-calibrates the touch pin + # detection. + pin.touch_calibrate() Except in the case of the pins marked **V2**, which offers the following API: @@ -172,6 +175,8 @@ pin_logo:: pin_logo.get_touches() # Sets the touch mode. Value can be either RESISTIVE or CAPACITIVE pin_logo.set_touch_mode(value) + # Re-calibrates the touch pin detection. + pin.touch_calibrate() pin_speaker, as the above ``MicroBitPin`` class, but does not include ``pin.is_touched()``. diff --git a/docs/pin.rst b/docs/pin.rst index 82b4e88dd..ad4e73b6f 100644 --- a/docs/pin.rst +++ b/docs/pin.rst @@ -197,6 +197,12 @@ its own to that. .. py:class:: MicroBitTouchPin + .. py:method:: touch_calibrate() + + Re-calibrates the touch pin detection. + This is useful when a conductive object is connected to the pin to + be used as a touch sensor. + .. py:method:: is_touched() Return ``True`` if the pin is being touched with a finger, otherwise