1

If I use the makecode editor to create the code, it generates:

pins.touch_set_mode(TouchTarget.P0, TouchTargetMode.CAPACITIVE)

However, if I try and run this, it can't find 'pins'.

Note: I then investigated further and found out how to do this before submitting my question...

AndyS
  • 725
  • 7
  • 17
  • Note: I just found the same detail as my answer below in the docs at https://microbit-micropython.readthedocs.io/en/v2-docs/tutorials/io.html – AndyS May 06 '21 at 09:09

1 Answers1

1

Capacitive mode can be set for each pin, e.g.

from microbit import *
...
pin0.set_touch_mode(pin0.CAPACITIVE)
...
if pin0.is_touched():
    ...

The last line checks whether the pin is touched - usually in a loop.

Hope this saves other people some time...

AndyS
  • 725
  • 7
  • 17