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

    How to "double click"

    Scheduled Pinned Locked Moved Cores
    4 Posts 2 Posters 9.3k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            cepics @Rop
            last edited by

            @rop Hi, is it compatible with espnow??

            tnks

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post