uBit.buttonAB

Overview

A MicroBitMultiButton mirrors the state of two MicroBitButtons using the message bus eventing mechanism. It provides a similar API and emits the same events as as a MicroBitButton.

Message Bus ID

Constant Value
MICROBIT_ID_BUTTON_AB 26

Message Bus Events

Constant Value
MICROBIT_BUTTON_EVT_DOWN 1
MICROBIT_BUTTON_EVT_UP 2
MICROBIT_BUTTON_EVT_CLICK 3
MICROBIT_BUTTON_EVT_LONG_CLICK 4
MICROBIT_BUTTON_EVT_HOLD 5
MICROBIT_BUTTON_EVT_DOUBLE_CLICK 6

API

Constructor


MicroBitMultiButton(
uint16_t
button1,
uint16_t
button2,
uint16_t
id)

Description

Constructor.

Create a representation of a virtual button, that generates events based upon the combination of two given buttons.

Parameters

uint16_t
button1 - the unique ID of the first button to watch.

uint16_t
button2 - the unique ID of the second button to watch.

uint16_t
id - the unique EventModel id of this MicroBitMultiButton instance.

Example
 multiButton(MICROBIT_ID_BUTTON_A, MICROBIT_ID_BUTTON_B, MICROBIT_ID_BUTTON_AB); 

isPressed


int
isPressed
()

Description

Tests if this MicroBitMultiButton instance is virtually pressed.

Returns

1 if both physical buttons are pressed simultaneously.

Example
 if(buttonAB.isPressed()) 
 display.scroll("Pressed!"); 

setEventConfiguration


void
setEventConfiguration
(
MicroBitButtonEventConfiguration
config)

Description

Changes the event configuration of this button to the given MicroBitButtonEventConfiguration. All subsequent events generated by this button will then be informed by this configuration.

Parameters

MicroBitButtonEventConfiguration
config - The new configuration for this button. Legal values are MICROBIT_BUTTON_ALL_EVENTS or MICROBIT_BUTTON_SIMPLE_EVENTS.

Example
 // Configure a button to generate all possible events. 
 buttonAB.setEventConfiguration(MICROBIT_BUTTON_ALL_EVENTS); 

 // Configure a button to suppress MICROBIT_BUTTON_EVT_CLICK and MICROBIT_BUTTON_EVT_LONG_CLICK events. 
 buttonAB.setEventConfiguration(MICROBIT_BUTTON_SIMPLE_EVENTS);