Hi,
I am having a problem with the long pressed function in the ClickButton library.
Test code:
#include "application.h"
#include "clickButton.h"
#include "SPI.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
// BUTTON define
#define EXTPIN D7
#define RUNPIN D3
// button define
ClickButton exitButton(EXTPIN, LOW, CLICKBTN_PULLUP);
ClickButton runButton(RUNPIN, LOW, CLICKBTN_PULLUP);
// Button results
int funcRunButtn = 0;
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
// init serial
Serial.begin(9600);
WiFi.on();
Particle.connect();
pinMode(EXTPIN, INPUT);
pinMode(RUNPIN, INPUT);
// Setup button timers (all in milliseconds / ms)
// (These are default if not set, but changeable for convenience)
exitButton.debounceTime = 20; // Debounce timer in ms
exitButton.multiclickTime = 250; // Time limit for multi clicks
exitButton.longClickTime = 1000; // time until "held-down clicks" register
runButton.debounceTime = 20; // Debounce timer in ms
runButton.multiclickTime = 250; // Time limit for multi clicks
runButton.longClickTime = 1000; // time until "held-down clicks" register
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
// Update button state
runButton.Update();
// Save click codes in LEDfunction, as click codes are reset at next Update()
if(runButton.clicks != 0) funcRunButtn = runButton.clicks;
if(funcRunButtn == 1)
{
Serial.println("Run BUTTON SINGLE click");
LngButtonTest();
}
funcRunButtn = 0;
delay(5);
}
void LngButtonTest()
{
bool isTestDone = false;
int fExtButtn = 0;
Serial.println("");
Serial.println("Enter Long Button Test Function");
Serial.println("");
while (!isTestDone)
{
exitButton.Update();
if(exitButton.clicks != 0)
{
fExtButtn = exitButton.clicks;
}
if(fExtButtn == 1)
{
Serial.println("EXIT BUTTON SINGLE click");
}
if(fExtButtn == -1)
{
Serial.println("EXIT BUTTON SINGLE LONG click");
isTestDone = true;
}
fExtButtn = 0;
delay(5);
}
}
Output:
Opening serial monitor for com port: "COM3"
Run BUTTON SINGLE click <--- I pressed the run button
Enter Long Button Test Function
EXIT BUTTON SINGLE LONG click <---- I pressed the exit button long pressed
Run BUTTON SINGLE click <---- I pressed the run button again
Enter Long Button Test Function
EXIT BUTTON SINGLE LONG click <<<< problem, automatic exit without pressed exit long button
It look like exitButton.Update(); still get the previous value (-1) in this case, button did not get reset even no pressed action. If I press the run button the third time, the problem does not happen.
Any one have encounter this before or any pointers? Thanks