Skip to content

On change callback support#13

Open
Narwhalsss360 wants to merge 2 commits intomadleech:masterfrom
Narwhalsss360:master
Open

On change callback support#13
Narwhalsss360 wants to merge 2 commits intomadleech:masterfrom
Narwhalsss360:master

Conversation

@Narwhalsss360
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant