Button
Button copied to clipboard
On change callback support
Feature
This feature was added to add support for event-driven style code by using callbacks or lambdas.
Motivation
- Event-driven style code may sometimes be easier to understand and read.
- lambda usage for simple subroutine defenition.
Implementation
Easy-use, overloaded begin() to begin(void (*)(void)). Just pass in a pointer to function when calling begin member, Even lambdas.
Usage
Simple
void myOnChangeCallback()
{
Serial.println("Button pressed, in callback!")
}
void setup()
{
button.begin(myOnChangeCallback);
Serial.begin(9600);
}
Lambda
void setup()
{
Serial.begin(9600);
button.begin([]() { Serial.println("Button pressed, sent using lambda!"); });
}
Extras
- Added an example for the new feature.
- Updated documentation.