Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickly switching between resistive and capacitive pin touch and checking state doesn't work #415

Open
microbit-carlos opened this issue Mar 26, 2024 · 0 comments
Milestone

Comments

@microbit-carlos
Copy link
Collaborator

microbit-carlos commented Mar 26, 2024

Easier to visualise in MakeCode:

Works Doesn't work
image image
input.onButtonPressed(Button.A, function () {
    basic.showString("r")
    pins.touchSetMode(
        TouchTarget.LOGO,
        TouchTargetMode.Resistive)
})
input.onButtonPressed(Button.B, function () {
    basic.showString("c")
    pins.touchSetMode(
        TouchTarget.LOGO,
        TouchTargetMode.Capacitive)
})
basic.forever(function () {
    if (input.logoIsPressed()) {
        basic.showIcon(IconNames.Heart)
    } else {
        basic.showIcon(IconNames.Sad)
    }
})
basic.forever(function () {
    pins.touchSetMode(
        TouchTarget.P0,
        TouchTargetMode.Resistive)
    if (input.pinIsPressed(TouchPin.P0)) {
        basic.showString("r")
    } else {
        basic.showIcon(IconNames.Sad)
    }
    pins.touchSetMode(
        TouchTarget.P0,
        TouchTargetMode.Capacitive)
    if (input.pinIsPressed(TouchPin.P0)) {
        basic.showString("c")
    } else {
        basic.showIcon(IconNames.Sad)
    }
})

Replicable in CODAL v0.2.66, also adding an extra isTouched() call in case it's needed:

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    while (true) {
        uBit.io.P0.isTouched(TouchMode::Capacitative);
        uBit.sleep(1);
        if (uBit.io.P0.isTouched(TouchMode::Capacitative)) {
            uBit.display.print('C');
        } else {
            uBit.display.clear();
        }
        uBit.sleep(300);

        uBit.io.P0.isTouched(TouchMode::Resistive);
        uBit.sleep(1);
        if (uBit.io.P0.isTouched(TouchMode::Resistive)) {
            uBit.display.print('R');
        } else {
            uBit.display.clear();
        }
        uBit.sleep(300);
    }
}

Related to this issue, but not quite the same. That issue is about only the uBit.logo (TouchButton) not working after setting the type to resistive, this is about none of the NRF52Pin touch pins working when switching modes quickly.

@microbit-carlos microbit-carlos added this to the v0.2.69 milestone May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant