Hello
I'm trying to use the MD_UISwitch library to decode analog switch. I'm experiencing some debounce. I'm using ESP12f (ESP8266) processor
How could I modify the timing of the library? sometime, A short press is decode like a long press and multiple reading for a single press.
3 single short keypress on button#2 is resulting to
Key_UP 2
LongP 2
Key_UP 2
Key_UP 2
LongP 2
Key_UP 2
My code is extract from the exemple
Martin
// Example showing use of the MD_UISwitch library
//
// Exercises different types of UI switches
//
// Prints the switch value on the Serial Monitor
// Allows setting of options to see their effect (see setup())
//
#include <MD_UISwitch.h>
#define TEST_ANALOG 1
#if TEST_ANALOG
#define TITLE "Analog Input"
const uint8_t ANALOG_SWITCH_PIN = A0; // switches connected to this pin
// These key values work for most LCD shields
MD_UISwitch_Analog::uiAnalogKeys_t kt[] =
{
//{ 12, 10, 'R' }, // Right
{ 30, 10, '4' }, // Up
{ 82, 15, '3' }, // Down
{ 293, 15, '2' }, // Left
{ 1024, 15, '1' }, // Select
};
MD_UISwitch_Analog S(ANALOG_SWITCH_PIN, kt, ARRAY_SIZE(kt));
#endif
void setup(void)
{
Serial.begin(57600);
S.begin();
//S.enableDoublePress(false);
S.enableLongPress(true);
//S.enableRepeat(false);
//S.enableRepeatResult(true);
}
void loop(void)
{
MD_UISwitch::keyResult_t k = S.read();
if (k != MD_UISwitch::KEY_NULL)
{
if (S.getKey() >= ' ')
{
if (k == MD_UISwitch::KEY_LONGPRESS)
{
Serial.print("LongP ");
Serial.println((char)S.getKey());
//Serial.print(" ");
}
if (k == MD_UISwitch::KEY_DPRESS)
{
Serial.print("Depr ");
Serial.println((char)S.getKey());
}
if (k == MD_UISwitch::KEY_UP)
{
Serial.print("Key_UP ");
Serial.println((char)S.getKey());
}
}
}
}