ButtonFever icon indicating copy to clipboard operation
ButtonFever copied to clipboard

Multiple buttons, each on a separate pin

Open KSumwalt opened this issue 4 years ago • 2 comments

Is it possible to have multiple buttons, each on a different pin? I tried this with no luck:

BfButton btn2(BfButton::STANDALONE_DIGITAL, 4, false, LOW); // I added a pulldown myself

void pressHandler (BfButton *btn, BfButton::press_pattern_t pattern) {
  Serial.print(btn->getID());
}

void setup() {
  btn1.onPress(pressHandler)
     .onDoublePress(pressHandler, 1000) // default timeout
     .onPressFor(pressHandler, 1000); // custom timeout for 1 second
  btn2.onPress(pressHandler)
     .onDoublePress(pressHandler, 1000) // default timeout
     .onPressFor(pressHandler, 1000); // custom timeout for 1 second
}

void loop() {
  btn1.read();
  btn2.read();
}```

I have enough pins that I do not need to worry about an array on a single pin and would rather not as I will be using the same code in multiple devices and readings may vary.

KSumwalt avatar Apr 20 '21 21:04 KSumwalt

Ugh.... Didn't mean to close it...

KSumwalt avatar Apr 20 '21 21:04 KSumwalt

Just add this line on top of your file?

BfButton btn1(BfButton::STANDALONE_DIGITAL, 4, false, LOW); // TODO: replace '4' with your PIN...

roelvan avatar Jun 27 '24 08:06 roelvan