was Pressed

Check if a button was pressed earlier.

input.buttonA.wasPressed()

The fact that a button was pressed earlier is remembered. Once was pressed is used, this fact is forgotten and the result is false the next time you check with was pressed (button state is reset). But, if you press the button again before you check with was pressed, it will tell you true.

Touch

If your board has pins or pads that work as touch inputs, then your code can use them just like buttons. Instead of saying button A or button B as the input source, use a pin name like pin A1.

if (input.pinA1.wasPressed()) {
    console.log("Hey, I was pressed.");
}

Read about touch sensors and using the pins as touch buttons.

Returns

  • a boolean: true if the button was pressed before, false if the button was not pressed before

Example

Log a message telling whether button A or B was pressed.

input.buttonB.onEvent(ButtonEvent.Click, function() {
    if (input.buttonA.wasPressed()) {
        console.log("Button A Pressed")
    } else {
        console.log("Button B Pressed")
    }
})

See also

is pressed, on event

Touch sensors