Skip to content

M5.BtnA.wasReleased() never true if M5.update() is intermediately called again #290

Description

@klues

I've the following scenario:

long lastCheck = 0;

void loop() {
   M5.update();
   if (millis() - lastCheck > 200) {
      lastCheck = millis();
      if (M5.BtnA.wasReleased()) {
         //do something - never reached!
      }
      // check other inputs via I2C
   }
}

So I'm checking for various inputs, the M5 buttons and other ones via I2C. I limit the rate of checking to 200ms. However in this code M5.BtnA.wasReleased() is never 1 or true, it seems like M5.update() internally resets the state, which shouldn't be the case IMO.

I'm doing this workaround, which works, but is not so clean:

long lastCheck = 0;
int btnAPressed = 0;

void loop() {
   M5.update();
   btnAPressed = btnAPressed || M5.BtnA.wasReleased();
   if (millis() - lastCheck > 200) {
      lastCheck = millis();
      if (btnAPressed) {
         //do something - works!
      }
      // check other inputs via I2C
      btnAPressed = 0;
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions