How to "double click"



  • Hi, all

    newbi question I know!!!

    How can I perform a double click event with M5 buttons on arduino envirement?

    ciao



  • I will start from here:

    #include <M5Stack.h>
    
    boolean State1 = false;
    boolean State2 = false;
    
    long buttonTimer = 0;
    long longPressTime = 250;
    
    boolean buttonActive = false;
    boolean longPressActive = false;
    
    void setup() {
      M5.begin();
      Serial.begin(115200);
    
    }
    
    void loop() {
    
      if (M5.BtnB. read() == HIGH) {
    
        if (buttonActive == false) {
    
          buttonActive = true;
          buttonTimer = millis();
    
        }
    
        if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {
    
          longPressActive = true;
          State1 = !State1;
          Serial.println("LONG");
    
        }
    
      } else {
    
        if (buttonActive == true) {
    
          if (longPressActive == true) {
    
            longPressActive = false;
    
          } else {
    
            State2 = !State2;
            Serial.println("SHORT");
    
          }
    
          buttonActive = false;
    
        }
    
      }
      M5.update();
    }
    


  • M5ez is a complete and very easy to use programming environment that offers many other nice things. Among them, you can very easily define what happens with short press, long press as well as combinations of two buttons.



  • @rop Hi, is it compatible with espnow??

    tnks