fork
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
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. | |
virtual int | isIdleCallbackNeeded () |
When added to the idleThreadComponents array, this function will be called to determine if and when data is ready. |
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:
-
name the physical pin on the processor that should be used as input. id the ID of the new MicroBitButton object. eventConfiguration Configures the events that will be generated by this MicroBitButton instance. Defaults to MICROBIT_BUTTON_ALL_EVENTS. mode the 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.
~MicroBitButton | ( | ) |
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.
Updates are determined by the isIdleCallbackNeeded() member function.
Reimplemented in MicroBitBLEManager, MicroBitEventService, MicroBitIOPinService, MicroBitAccelerometer, MicroBitCompass, and MicroBitThermometer.
Definition at line 127 of file MicroBitComponent.h.
virtual int isIdleCallbackNeeded | ( | ) | [virtual, inherited] |
When added to the idleThreadComponents array, this function will be called to determine if and when data is ready.
- Note:
- override this if you want to request to be scheduled as soon as possible.
Reimplemented in MicroBitAccelerometer, MicroBitCompass, and MicroBitThermometer.
Definition at line 138 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:
-
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. 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.
Generated on Tue Jul 12 2022 19:47:36 by 1.7.2