Noiasca Tool Kit
Several helper functions and classes to make life with Arduino easier
Public Member Functions | List of all members
Button Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Button()

Button::Button ( byte  attachTo,
bool  active = LOW 
)
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.

Parameters
attachTothe GPIO for the button
activeLOW (default) - if button connects to GND, HIGH if button connects to VCC

Member Function Documentation

◆ begin()

void Button::begin ( )
inline

set the pin to the proper state

Call this function in your setup(). The pinMode will be set according to your constructor.

◆ isPressed()

bool Button::isPressed ( )
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.

Returns
true if button is currently pressed (without any debounce logic)

◆ setOnPress()

void Button::setOnPress ( void(*)()  cbOnPress)
inline

set the callback for on press events ("raising")

Parameters
cbOnPressthe callback function to be called

◆ setOnRelease()

void Button::setOnRelease ( void(*)()  cbOnRelease)
inline

set the callback for on release events ("falling")

Parameters
cbOnReleasethe callback function to be called

◆ wasPressed()

bool Button::wasPressed ( uint32_t  currentMillis = millis())
inline

indicate if button was pressed since last call

Returns
true if button was pressed since last call - debounce
Parameters
currentMillisa millis() timestamp. Optional. If omitted actual millis() will be used

◆ wasReleased()

bool Button::wasReleased ( uint32_t  currentMillis = millis())
inline

indicate if button was released since last call

Returns
TRUE if button was released since last call - debounce
Parameters
currentMillisa millis() timestamp. Optional. If omitted actual millis() will be used.

◆ update()

void Button::update ( uint32_t  currentMillis = millis())
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.

Parameters
currentMillisa millis() timestamp. Optional. If omitted actual millis() will be used.