mathertel / OneButton

An Arduino library for using a single button for multiple purpose input.
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
Other
920 stars 230 forks source link

New Callback attachHappenAfterTickNumber added #108

Closed volkanunal closed 7 months ago

volkanunal commented 1 year ago

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();
}
mathertel commented 7 months ago

This seems not to be a very broadly required extension and with the current version of the library this can be achieved using the attachMultiClick callback that can get the number of ticks using the getNumberClicks() function.

Thanks for supporting.