ButtonFever
ButtonFever copied to clipboard
Multiple buttons, each on a separate pin
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.
Ugh.... Didn't mean to close it...
Just add this line on top of your file?
BfButton btn1(BfButton::STANDALONE_DIGITAL, 4, false, LOW); // TODO: replace '4' with your PIN...