Button icon indicating copy to clipboard operation
Button copied to clipboard

On change callback support

Open Narwhalsss360 opened this issue 3 years ago • 0 comments

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.

Narwhalsss360 avatar Jun 30 '22 05:06 Narwhalsss360