Open pruge opened 6 months ago
Same here.
Adding a 100ms delay and a counter to the example code shows that the click event occurs within 300ms, perhaps related to debounce state changes?
unsigned int counter = 0;
void loop() {
// read your own source of input:
bool isPressed = (digitalRead(PIN_INPUT) == LOW);
// call tick frequently with current push-state of the input
button->tick(isPressed);
Serial.println(counter);
counter++;
delay(100);
}
* Executing task: platformio device monitor --environment megaatmega2560
--- Terminal on /dev/ttyUSB0 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
0
1
2
Click:me
3
4
Thanks for your work :)
Same here, tried to force tick in high or low state before running loop. Always fires click. Tried on UNO, Zero, Arduino ESP32 Nano.
Anyone has a (temp) fix for this?
I've investigate a little bit in this issue, and it seems to be related to the -1
initialized value of debouncedPinLevel
. Set this value to 0
fix this issue (OneButton.h#L244, idk if there are any side effects):
int debouncedPinLevel = 0;
I think this is related to the debounce timer, when the timer reaches the debounce value the activityLevel
goes from -1
to 0
, which is deterministic in the first step of the _fsm()
:
case OneButton::OCS_INIT:
...
if (activeLevel) { // -1 trigger this condition !!!!
_newState(OneButton::OCS_DOWN);
...
}
break;
Here is my troubleshooting setup:
loop()
Serial.print
each states inside the _fsm()
Serial.print
activeLevel inside tick(bool activeLevel)
My temp solution was:
`/ callbacks Button 1 /
void callback_Class_OneButton_BUTTON1_click() { // Bug in One Button library Version 2.5.0, first call is a dud if (variable_Button1_firstclick == false) { variable_Button1_firstclick = true; return; } `
But your solution @XavierBrassoud
int debouncedPinLevel = 0;
Seems to work fine. Thank you.
The click event is fired as soon as the system starts. This is an unintentional click event. Is this correct behavior?
I'm using an ESP32 board.