🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to "double click"

    Cores
    2
    4
    8.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cepics
      last edited by cepics

      Hi, all

      newbi question I know!!!

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

      ciao

      1 Reply Last reply Reply Quote 0
      • C
        cepics
        last edited by

        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();
        }
        
        1 Reply Last reply Reply Quote 0
        • RopR
          Rop
          last edited by

          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.

          C 1 Reply Last reply Reply Quote 0
          • C
            cepics @Rop
            last edited by

            @rop Hi, is it compatible with espnow??

            tnks

            1 Reply Last reply Reply Quote 0
            • First post
              Last post