Skip to content

Commit c024951

Browse files
microbit-markmicrobit-carlos
authored andcommitted
V2 docs: Add pin set_touch_mode() (#701)
* V2 docs: add set_touch_mode() * V2 docs: add set_touch_mode() to micropython API doc
1 parent 00b59d3 commit c024951

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

docs/microbit_micropython_api.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ Provide digital and analog input and output functionality, for the pins in the
112112
connector, the **V2** logo and the **V2** speaker. Some pins are connected
113113
internally to the I/O that drives the LED matrix and the buttons.
114114

115-
Each pin is provided as an object directly in the ``microbit`` module. This keeps the API relatively flat, making it very easy to use:
115+
Each pin is provided as an object directly in the ``microbit`` module. This
116+
keeps the API relatively flat, making it very easy to use:
116117

117118
* pin0
118119
* pin1
@@ -144,13 +145,18 @@ Each of these pins are instances of the ``MicroBitPin`` class, which offers the
144145
# Only available for touch pins 0, 1, and 2. Returns boolean if the pin
145146
# is touched
146147
pin.is_touched()
148+
# Only available for touch pins 0, 1, 2 and on micro:bit V2 also the logo.
149+
# Sets the touch mode. Value can be either RESISTIVE or CAPACITIVE
150+
pin.set_touch_mode(value)
147151

148152
Except in the case of the pins marked **V2**, which offers the following API::
149153
150154
pin_logo::
151155

152156
# returns boolean for logo touch pin
153157
pin_logo.is_touched()
158+
# Sets the touch mode. Value can be either RESISTIVE or CAPACITIVE
159+
pin.set_touch_mode(value)
154160

155161
pin_speaker:
156162

docs/pin.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ Pin Functions
2626

2727
`Edge connector and pinout <https://tech.microbit.org/hardware/edgeconnector/#edge-connector-pins>`_
2828

29-
Those pins are available as attributes on the ``microbit``
30-
module:``microbit.pin0`` - ``microbit.pin20``.
29+
This table summarises the pins available, their types and what
30+
they are internally connected to. The pins are available as attributes on the
31+
``microbit`` module: ``microbit.pin0`` - ``microbit.pin20``.
3132

3233
+-----+---------+----------+-----------------+
3334
| Pin | Type | Function | Function **V2** |
@@ -72,9 +73,6 @@ module:``microbit.pin0`` - ``microbit.pin20``.
7273
| 20 | Digital | I2C SDA | I2C SDA |
7374
+-----+---------+----------+-----------------+
7475

75-
The above table summarizes the pins available, their types (see below) and what
76-
they are internally connected to.
77-
7876
The latest micro:bit device **V2** has two additional pins that you can access
7977
in MicroPython, but that are not available via the edge connector:
8078

@@ -206,7 +204,7 @@ its own to that.
206204
The default touch mode for the pins on the edge connector is
207205
`resistive`. The default for the logo pin **V2** is `capacitive`.
208206

209-
**Resitive touch**
207+
**Resistive touch**
210208
This test is done by measuring how much resistance there is between the
211209
pin and ground. A low resistance gives a reading of ``True``. To get
212210
a reliable reading using a finger you may need to touch the ground pin
@@ -217,6 +215,15 @@ its own to that.
217215
using a finger as a conductor. `Capacitive touch
218216
<https://www.allaboutcircuits.com/technical-articles/introduction-to-capacitive-touch-sensing>`_
219217
does not require you to make a ground connection as part of a circuit.
218+
219+
.. py:method:: set_touch_mode(value)
220+
221+
.. note::
222+
The default touch mode for the pins on the edge connector is
223+
`resistive`. The default for the logo pin **V2** is `capacitive`.
224+
225+
Set the touch mode for the given pin. Value can be either ``CAPACITIVE``
226+
or ``RESISTIVE``. For example, ``pin0.set_touch_mode(pin0.CAPACITIVE)``.
220227

221228
The pull mode for a pin is automatically configured when the pin changes to an
222229
input mode. Input modes are when you call ``read_analog`` / ``read_digital`` /

0 commit comments

Comments
 (0)