MajicDesigns / MD_UISwitch

Uniformly encapsulate different types of switches as user input devices
GNU Lesser General Public License v2.1
40 stars 17 forks source link

Unable to get a long press response from MD_UISwitch_Digital #12

Closed cssinate closed 3 years ago

cssinate commented 3 years ago

IMPORTANT

Before submitting this issue

Subject of the issue

I am unable to get a long press event to fire.

Your Environment

Library Version: 2.1.0 Arduino IDE version: 1.8.13 Hardware model/type: ESP8266 OS and Version: Windows 10

Steps to Reproduce

Using a momentary-on switch wired like this, I've been able to get a single press response and a double press response, but not a long press response.

Expected Behaviour

When I press and hold the button, after I let go, a long press response should have been received.

Actual Behaviour

If I press and hold the button, I receive a single press response while the button is still held down. I do not ever get a long press response.

Code Demonstrating the Issue

I'm running the code block before. On the button, I will do a single press, then a double press, then press and hold for long press and paste the Serial Monitor output.

#include <MD_UISwitch.h>
#define BUTTON_PIN                14    // GPIO Pin
MD_UISwitch_Digital Button(BUTTON_PIN, HIGH);

void setup() {
    Serial.begin(115200);
    Button.begin();
    Button.enableDoublePress(true);
    Button.enableLongPress(true);
    Button.enableRepeatResult(true);
}

void loop() {
    MD_UISwitch::keyResult_t k = Button.read();
    switch(k) {
    case MD_UISwitch::KEY_UP:        Serial.print("\nKEY_UP ");     break;
    case MD_UISwitch::KEY_DOWN:      Serial.print("\n\nKEY_DOWN ");   break;
    case MD_UISwitch::KEY_PRESS:
        Serial.print("Single press");
        Serial.println("\n");
        break;
    case MD_UISwitch::KEY_DPRESS:
        Serial.print("Double press");
        Serial.println("\n");
        break;
    case MD_UISwitch::KEY_LONGPRESS:
        Serial.print("Long press");
        Serial.println("\n");
        break;
    }
}

The Serial Monitor reads:

KEY_DOWN 
KEY_UP Single press

KEY_DOWN 
KEY_UP 

KEY_DOWN 
KEY_UP Double press

KEY_DOWN Single press

KEY_UP 

Thanks

I really appreciate the library and you taking the time to address the issue. I'm pretty new at this Arduino stuff, and the project I'm working on is the first C++ I've ever written. If it's user error, I humbly apologize for wasting your time!

MajicDesigns commented 3 years ago

Wired up the switch according to your link and tested your code on a Uno. Seems to work fine - I get a long press.

Are you able to try this on the same processor rather than ESP8266?