waitForButtonPress()

Wait for the board’s built-in button to be pressed, possibly with timeout. The button is labeled “BUT” on the board’s silkscreen. Its pin number is the constant BOARD_BUTTON_PIN.

Library Documentation

uint8 waitForButtonPress(uint32 timeout_millis = 0)

Wait until the button is pressed and released, timing out if no press occurs.

The button pin must have its mode set to INPUT. This can be accomplished portably over all LeafLabs boards by calling pinMode(BOARD_BUTTON_PIN, INPUT).

Parameters:
  • timeout_millis -

    Number of milliseconds to wait until the button is pressed. If timeout_millis is left out (or 0), wait forever.

Return:

true, if the button was pressed; false, if the timeout was reached.

See:

pinMode()

Example

This example sets up the board’s button pin as an input, then prints a message very time the button is pressed.

void setup() {
    pinMode(BOARD_BUTTON_PIN, INPUT);
}

void loop() {
    waitForButtonPress();
    SerialUSB.println("You pressed the button!");
}