FloKra d9e47579fd 0.5.0 2020-01-09 4 years ago
..
examples d9e47579fd 0.5.0 2020-01-09 4 years ago
src d9e47579fd 0.5.0 2020-01-09 4 years ago
.gitignore d9e47579fd 0.5.0 2020-01-09 4 years ago
.travis.yml d9e47579fd 0.5.0 2020-01-09 4 years ago
LICENSE.md d9e47579fd 0.5.0 2020-01-09 4 years ago
README.md d9e47579fd 0.5.0 2020-01-09 4 years ago
keywords.txt d9e47579fd 0.5.0 2020-01-09 4 years ago
library.json d9e47579fd 0.5.0 2020-01-09 4 years ago
library.properties d9e47579fd 0.5.0 2020-01-09 4 years ago

README.md

r89m Push Button

This library makes working with push buttons easy.

Easily handle button events such as onPress, onHold, onHoldRepeat and onRelease. The same callback functions can be used with multiple buttons, helping to keep your code cleaner and more manageable.

This library relies on you having both r89m Buttons and Bounce2 libraries downloaded and available to the Arduino IDE.

Examples

Checkout the examples folder to show you how easy it is to use!

Methods

boolean update()

Update the button state - this will call any callbacks that are necessary. Returns true if the state changes.

boolean is(Button& btn)

Return whether or not the button is the same as the btn passed

boolean isPressed()

Return whether or not the button is currently pressed.

void configureButton(configureButtonCallback)

Allows the underlying button object to be configured on a per-button basis. Useful if you want to tinker with low-level features of the button interface; eg. Bounce.


c++ void configureBounce2ButtonCallback(Bounce& bounceButton){ // You can now access the underlying Bounce object, and use all the methods provided // ie bounceButton.setInterval(20); // Set the debouncing interval }


## Callbacks
### ```CallbackAttachedResponse onPress(onPressCallbackFunction)```

onPressCallbackFunction``` is a function which will be called as soon as the button is pressed. It must be defined with the parameters shown below

void callThisFunctionOnPress(Button& btn){
  // btn is a reference to the button that was pressed.
}

CallbackAttachedResponse onRelease

There are 3 variations of onRelease:

CallbackAttachedResponse onRelease(onReleaseCallbackFunction)

c++ void callThisFunctionOnRelease(Button& btn, uint_16t duration){ // btn is a reference to the button that was pressed // duration is how long the button was pressed for }


#### ```CallbackAttachedResponse onRelease(uint_16t wait, onReleaseCallbackFunction)```

As above, plus:

waitif the button is held for at-leastwaitmsonReleaseCallbackFunction``` will be called.

CallbackAttachedResponse onRelease(uint_16t wait, uint_16t max_wait, onReleaseCallbackFunction)

As above, plus:



### ```CallbackAttachedResponse onHold(uint_16t duration, onHoldCallbackFunction)```

durationhow long the button must be held beforeonHoldCallbackFunction``` is called.


c++ void callThisFuntionOnHold(Button& btn, uint_16t duration){ // btn is a reference to the button that was held // duration is how long the button was held for }


### ```CallbackAttachedResponse onHoldAndRepeat(uint_16t duration, uint_16t repeat_every, onHoldAndRepeatCallbackFunction)```

durationhow long the button must be held beforeonHoldAndRepeatCallbackFunction``` is called.

onHoldAndRepeatCallbackFunction``` is a function which is called repeatedly when the button is held. It must be defined with the parameters shown below

void callThisFunctionOnHoldAndRepeat(Button& btn, uint16_t duration, uint8_t repeat_count){
  // btn is a reference to the button that was held
  // duration is how long the button has been held for
  // repeat_count is the number of times the callback has been called
}

Enums

CallbackAttachedResponse


attNoMoreRoomreturned when a callback could not be attached because there is not enough room. CheckMAX_CALLBACKS_PER_BUTTON```.

Constants

MAX_CALLBACKS_PER_BUTTON (default=3)

Defines the maximum number of callbacks per button. Increasing this number will allow more callbacks but will use marginally more memory and processing power. This can be changed on a sketch by sketch basis, simply define #MAX_CALLBACKS_PER_BUTTON before your #includes.