Noiasca Tool Kit
Several helper functions and classes to make life with Arduino easier
|
read a button More...
#include <Noiasca_button.h>
Public Member Functions | |
Button (byte attachTo, bool active=LOW) | |
constructor for a button More... | |
void | begin () |
set the pin to the proper state More... | |
bool | isPressed () |
read if button is pressed More... | |
void | setOnPress (void(*cbOnPress)()) |
set the callback for on press events ("raising") More... | |
void | setOnRelease (void(*cbOnRelease)()) |
set the callback for on release events ("falling") More... | |
bool | wasPressed (uint32_t currentMillis=millis()) |
indicate if button was pressed since last call More... | |
bool | wasReleased (uint32_t currentMillis=millis()) |
indicate if button was released since last call More... | |
void | update (uint32_t currentMillis=millis()) |
run member function More... | |
read a button
This is just a simple class to read button presses. The button will be debounced by software. You can replace this implementation with any other library.
|
inline |
constructor for a button
The constructor takes the GPIO as parameter. If you omit the second parameter, the library will activate the internal pullup resistor and the button should connect to GND. If you set the second parameter to HIGH, the button is active HIGH. The button should connect to VCC. The internal pullups will not be used.
attachTo | the GPIO for the button |
active | LOW (default) - if button connects to GND, HIGH if button connects to VCC |
|
inline |
set the pin to the proper state
Call this function in your setup(). The pinMode will be set according to your constructor.
|
inline |
read if button is pressed
This is similar to a native "digitalRead" but the returned logic depends on the active status during creation of the the instance. If the button is active LOW (default), this member function will return true if the button is closed to GND.
|
inline |
set the callback for on press events ("raising")
cbOnPress | the callback function to be called |
|
inline |
set the callback for on release events ("falling")
cbOnRelease | the callback function to be called |
|
inline |
indicate if button was pressed since last call
currentMillis | a millis() timestamp. Optional. If omitted actual millis() will be used |
|
inline |
indicate if button was released since last call
currentMillis | a millis() timestamp. Optional. If omitted actual millis() will be used. |
|
inline |
run member function
This is the "run" function. Call this function in loop() to read the button. This function uses by default the actual millis() to determine, if callback functions needs to be called.
currentMillis | a millis() timestamp. Optional. If omitted actual millis() will be used. |