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

PINs set to Capacitive Mode last don't wont (excluding P0) #6072

Closed
maybdev opened this issue Jan 20, 2025 · 7 comments
Closed

PINs set to Capacitive Mode last don't wont (excluding P0) #6072

maybdev opened this issue Jan 20, 2025 · 7 comments

Comments

@maybdev
Copy link

maybdev commented Jan 20, 2025

My Problem
On my micro:bit v2.21, when I set all my pins to Capacitive Mode, the last one that has been set doesn't get detected with the pin_is_pressed function. But if P0 is the last one set to Capacitive, then they all work (including P0).

How To Reproduce

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

def on_forever():
    if input.pin_is_pressed(TouchPin.P0):
        music.ring_tone(440)
    elif input.pin_is_pressed(TouchPin.P1):
        music.ring_tone(494)
    elif input.pin_is_pressed(TouchPin.P2):
        music.ring_tone(523)
    else:
        music.stop_all_sounds()
basic.forever(on_forever)

In this code, when loaded onto my micro:bit, when I touch P0, then it rings tone 440, if I touch P1, it rings tone 494, but if I touch P2, then nothing will happen. At the very top of the code, if you change P1 to be set to Capacitive last, then P2 will work and ring tone 523, but P1 wont work at all, and if you change P0 to be set to Capacitive last, then ALL the pins will work properly!

More Info
If I use the on_pin_pressed function then all pins will work properly no matter to order of setting, but if the on_pin_pressed function AND the pin_is_pressed function are used at the same time, then the last pin set to Capacitive Mode (excluding P0) will neither work with on_pin_pressed OR pin_is_pressed.

And the bug only occurs on my micro:bit and not in the simulator.

@abchatra
Copy link
Collaborator

@carlosperate ?

@maybdev
Copy link
Author

maybdev commented Jan 22, 2025

@abchatra

Sorry, I don't understand.

@maybdev
Copy link
Author

maybdev commented Jan 22, 2025

Ok, if I use LED blocks for the pin presses, this bug doesn't happen.
I, myself, am very confused about what this bug even is, and it can be bypassed, so i'm just going to close this bug report.

@maybdev maybdev closed this as completed Jan 22, 2025
@martinwork
Copy link
Contributor

@maybdev @microbit-carlos @abchatra
stop all sounds breaks capacitive touch on the last pin.
https://github.com/microsoft/pxt-microbit/blob/master/libs/core/music.ts#L521

It seems to have always been the case, back to MakeCode v3.

In this example, P2 works until button A is pressed.
https://makecode.microbit.org/_KgCbDP7at7f6
Image

@martinwork
Copy link
Contributor

martinwork commented Jan 22, 2025

rest for 1 beat breaks it too
https://makecode.microbit.org/_3E2AwfLmJJ5E

In fact it seems any digital/analogue read/write of P0 or P1 breaks P2 touch. I can repeat that in C++.

@maybdev The tones example can work with the audio pin disabled
https://makecode.microbit.org/_WfmUCH1Lt1hw

@microbit-carlos
Copy link
Collaborator

@abchatra looks like this is a valid issue in CODAL which is exposed in MakeCode. Up to you if you prefer to keep this close or re-open it until it is resolved.
Thanks Martin for creating the CODAL issue in:

@abchatra
Copy link
Collaborator

Lets close this and track in codal repo.

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

4 participants