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

isPressed() returns false when button is pressed down while resetting the board #388

Open
microbit-carlos opened this issue Nov 2, 2023 · 2 comments
Labels
Milestone

Comments

@microbit-carlos
Copy link
Collaborator

Simple program, on startup if Button A is pressed it displays the letter A, otherwise ?:

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    if (uBit.buttonA.isPressed()) {
        uBit.display.print('A');
    } else {
        uBit.display.print('?');
    }
    while (true) uBit.sleep(1000);
}

MICROBIT.hex.zip

  • With the board powered off, keeping button A pressed down and inserting the USB cable shows A
  • While powered on, keeping the button A pressed down, and pressing the reset button shows ?
@microbit-carlos
Copy link
Collaborator Author

microbit-carlos commented Nov 2, 2023

With this provided codal.json file, the issue is resolved with MICROBIT_BLE_PAIRING_MODE=1, but breaks with MICROBIT_BLE_PAIRING_MODE=0.

{
    "target": {
        "name": "codal-microbit-v2",
        "url": "https://github.com/lancaster-university/codal-microbit-v2",
        "branch": "master",
        "type": "git"
    },
    "config":{
        "DEVICE_BLE": 1,
        "MICROBIT_BLE_ENABLED" : 0,
        "MICROBIT_BLE_PAIRING_MODE": 0
    }
}

@microbit-carlos
Copy link
Collaborator Author

With MICROBIT_BLE_PAIRING_MODE =0, adding uBit.sleep(100) before the uBit.buttonA.isPressed() (which happens in uBit.init() when pairing mode is enabled) seems to resolve the issue. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants