OneButton icon indicating copy to clipboard operation
OneButton copied to clipboard

New Callback attachHappenAfterTickNumber added

Open embedded4ever opened this issue 3 years ago • 0 comments

Hi, I have added a new callback to the system. It is called when the user presses the desired amount of buttons.

Here is the example usage :

#include <Arduino.h>
#include "src/OneButton.h">

class Button{
private:
  OneButton button;
  int value;
public:
  explicit Button(uint8_t pin):button(pin) {
    button.setAfterTicks(5);
    button.attachHappenAfterTickNumber([](void *scope){ ((Button *) scope)->happenAfterTick();}, this);
  }

  void handle(){
    button.tick();
  }

  void happenAfterTick() {
    Serial.println("Function called after counts");
  }
};

Button button(8);

void setup() {
  Serial.begin(115200);
}

void loop() {
  button.handle();
}

embedded4ever avatar Aug 11 '22 20:08 embedded4ever