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

    Simulate button press?

    Cores
    3
    5
    10.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.
    • B
      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
        heybin
        last edited by

        hello, gpio 38 in esp32 only input

        1 Reply Last reply Reply Quote 0
        • B
          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
            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
              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
              • First post
                Last post