M5Stack icon indicating copy to clipboard operation
M5Stack copied to clipboard

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

Open klues opened this issue 2 years ago • 0 comments

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;
   }
}

klues avatar May 09 '22 09:05 klues