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

    Simulate button press?

    Scheduled Pinned Locked Moved Cores
    5 Posts 3 Posters 12.0k 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.
    • B Offline
      BrianR
      last edited by BrianR

      Is there a way to simulate a button press in code? I'm looking for a M5.BtnA.press(). I've tried pulling GPIO pins low for a quick delay, then back high again, like this:

          digitalWrite(38, LOW);
          delay(100);
          digitalWrite(38, HIGH);
      

      Not only does that not work, I'm afraid I'd lose debouncing. Any ideas?

      1 Reply Last reply Reply Quote 0
      • H Offline
        heybin
        last edited by

        hello, gpio 38 in esp32 only input

        1 Reply Last reply Reply Quote 0
        • B Offline
          BrianR
          last edited by

          Yup, @heybin, you're indeed right. Short of soldering a wire from an available GPIO to the switch itself, I don't see anything in the buttons library that could even be modified to allows for this functionality. It's either so simple that I just can't see the answer, or impossible (without a soldering iron involved)...

          1 Reply Last reply Reply Quote 0
          • lukasmaximusL Offline
            lukasmaximus
            last edited by

            I'm wondering what is your purpose for simulating a button press? maybe there could be an alternative solution for your problem

            1 Reply Last reply Reply Quote 0
            • B Offline
              BrianR
              last edited by

              Well, I have a couple of spots in my project that a button press would make things very easy. For example, I'm using M5ez for my interface, and use Blynk to display events on the M5 screen. I have backlight timeout set to 30 seconds. A new event doesn't turn the backlight back on, but a keypress does. So, in my if (newEvent) loop, I could have a M5.BtnA.press(), that would wake up the screen. Can I go into the M5ez library, figure out what happens after a real button press to wake the screen and replicate that? Yes, of course, and I have certainly tried that, but some of the items that need to be set are private, so calling them from a main loop is problematic. Rewriting that stuff so it's all public might work, but that solves one problem. I'd also like menus to time out - if there's no activity after going into a menu, I'd like it to time out and go back to the main menu. Again, code can certainly make that happen, but a M5.BtnA.press() would be a lot easier to implement... Does this make sense?

              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