Events

The input.onEvent block allows to respond to clicks, double clicks and other classic button events. It can be mounted on button A, B or both A+B together. Internally, MakeCode takes care of handling the pin state, debouncing, timing and other fun stuff.

Live data

You can read the live button status using input.isPressed. In some situations, you might miss clicks because your program was busy while the user was pressing. In such case, you can also use input.wasPressed which keeps track if the button was pressed between successive calls.

Example

The click event on button A is used to play a sound. The state of button B is checked in a forever loop to switch between red and blue on the neopixels.

This guide was first published on Jun 07, 2017. It was last updated on Jun 07, 2017.

This page (Buttons) was last updated on Jun 07, 2017.

Text editor powered by tinymce.