mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal

Dependencies:   BLE_API nRF51822 mbed-dev-bin

Dependents:   microbit Microbit IoTChallenge1 microbit ... more

Embed: (wiki syntax)

« Back to documentation index

MicroBitButton Class Reference

MicroBitButton Class Reference

Class definition for MicroBit Button. More...

#include <MicroBitButton.h>

Inherits MicroBitComponent.

Public Member Functions

 MicroBitButton (PinName name, uint16_t id, MicroBitButtonEventConfiguration eventConfiguration=MICROBIT_BUTTON_ALL_EVENTS, PinMode mode=PullNone)
 Constructor.
int isPressed ()
 Tests if this Button is currently pressed.
void setEventConfiguration (MicroBitButtonEventConfiguration config)
 Changes the event configuration used by this button to the given MicroBitButtonEventConfiguration.
virtual void systemTick ()
 periodic callback from MicroBit system timer.
 ~MicroBitButton ()
 Destructor for MicroBitButton, where we deregister this instance from the array of fiber components.
virtual void idleTick ()
 The idle thread will call this member function once the component has been added to the array of idle components using fiber_add_idle_component.

Detailed Description

Class definition for MicroBit Button.

Represents a single, generic button on the device.

Definition at line 71 of file MicroBitButton.h.


Constructor & Destructor Documentation

MicroBitButton ( PinName  name,
uint16_t  id,
MicroBitButtonEventConfiguration  eventConfiguration = MICROBIT_BUTTON_ALL_EVENTS,
PinMode  mode = PullNone 
)

Constructor.

Create a software representation of a button.

Parameters:
namethe physical pin on the processor that should be used as input.
idthe ID of the new MicroBitButton object.
eventConfigurationConfigures the events that will be generated by this MicroBitButton instance. Defaults to MICROBIT_BUTTON_ALL_EVENTS.
modethe configuration of internal pullups/pulldowns, as defined in the mbed PinMode class. PullNone by default.
 buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A);

Definition at line 48 of file MicroBitButton.cpp.

Destructor for MicroBitButton, where we deregister this instance from the array of fiber components.

Definition at line 159 of file MicroBitButton.cpp.


Member Function Documentation

virtual void idleTick (  ) [virtual, inherited]

The idle thread will call this member function once the component has been added to the array of idle components using fiber_add_idle_component.

Reimplemented in MicroBitBLEManager, MicroBitEventService, MicroBitIOPinService, MicroBitAccelerometer, MicroBitCompass, and MicroBitThermometer.

Definition at line 133 of file MicroBitComponent.h.

int isPressed (  )

Tests if this Button is currently pressed.

 if(buttonA.isPressed())
     display.scroll("Pressed!");
Returns:
1 if this button is pressed, 0 otherwise.

Definition at line 151 of file MicroBitButton.cpp.

void setEventConfiguration ( MicroBitButtonEventConfiguration  config )

Changes the event configuration used by this button to the given MicroBitButtonEventConfiguration.

All subsequent events generated by this button will then be informed by this configuraiton.

Parameters:
configThe 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.
 buttonA.setEventConfiguration(MICROBIT_BUTTON_ALL_EVENTS);

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

Definition at line 74 of file MicroBitButton.cpp.

void systemTick (  ) [virtual]

periodic callback from MicroBit system timer.

Check for state change for this button, and fires various events on a state change.

Reimplemented from MicroBitComponent.

Definition at line 84 of file MicroBitButton.cpp.