More than 1 sec Long press Not working
Hello, First of all thanks for this library, it's very interesting. I'm trying the MultiClicks example in a Esp32.
I found that when I do more than once short click it always calls the same function. In the following code "2 something" is displayed in loop in the serial monitor.
if(LEDfunction == 2){
doSomethingWhenTwoShortClicks();
}
void doSomethingWhenTwoShortClicks(){
Serial.println("2 something");
}
Also found that it never reaches the long press for more than 1 sec. The following code always would call doSomethingLongPress();
if(LEDfunction == -1){
doSomethingLongPress();
}
if(LEDfunction == -2){
doSomethingLongPressTWO();
}
Hi, it's been a while since you posted this but I have had the same problem just today. There are some errors in the library. I fixed this issue making these changes to the file ClickButton.cpp. Line 152 (I've commented the original code):
// Check for "long click"
//if (depressed && (now - _lastBounceTime > longClickTime)) <-- Error in parenthesis
if (depressed && (now - _lastBounceTime) > longClickTime)
{
// negative count for long clicks
//clicks = 0 - _clickCount;
clicks = 0 - (now - _lastBounceTime)/longClickTime; // Calculate the seconds from press to release
_clickCount = 0;
if(clicks != 0) changed = true;
}
It works for me. Hope it helps
You can also modify the last IF condition if you don't want the button state changes while being pressed:
if(clicks != 0 && clicks!=Prev_clicks) changed = true;
The whole code block will become:
// Check for "long click"
//if (depressed && (now - _lastBounceTime > longClickTime))
if (depressed && (now - _lastBounceTime) > longClickTime)
{
int Prev_clicks=clicks;
// negative count for long clicks
//clicks = 0 - _clickCount;
clicks = 0 - (now - _lastBounceTime)/longClickTime;
_clickCount = 0;
if(clicks != 0 && clicks!=Prev_clicks) changed = true;
}