microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
43 stars 24 forks source link

Add set and get touch modes for touch pins #14

Closed microbit-carlos closed 3 years ago

microbit-carlos commented 3 years ago

To be able to set and get the touch model for the logo and touch pins, between capacitive and resistive.

The default modes should be (I believe this part is implemented already):

jaustin commented 3 years ago

The uBit object already constructs these with the appropriate defaults, but there should be a way to switch them over to the other modes. This is done in CODAL by calling isTouched() with an argument to determine the mode

https://github.com/lancaster-university/codal-nrf52/blob/master/source/NRF52Pin.cpp#L520

Here's usage in MakeCode... https://github.com/microsoft/pxt-microbit/blob/master/libs/core/touchmode.cpp#L40

Pins that can have their touchmode changed

(this list is defined by the hardware because these pins have 10M pullups that make the resistive mode work)

logo is it's own class with only `is_touched()' so that needs extending, as do pin0,1,2

Proposed Python API:

pin0.set_touch_mode(pin0.CAPACITIVE)
pin_logo.set_touch_mode(pin_logo.RESISTIVE)
dpgeorge commented 3 years ago

pin.set_touch_mode(mode) method and corresponding constants were added in cbc3cfccb7a00ea40d377f2a49628625b32efdf8

microbit-carlos commented 3 years ago

Gave this a test and all looks good, thanks Damien!