Skip to content

Multiple buttons, each on a separate pin #2

Description

@KSumwalt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions