Home>

I want to change the screen brightness by briefly pressing the power button on the M5stick C.

Corresponding source code
#define PWR_BTN_SHORT_PRESS 2
int screen = 0
void loop () {
  int axpButton = M5.Axp.GetBtnPress ();
  if (axpButton == PWR_BTN_SHORT_PRESS) {
      M5.Axp.ScreenBreath (0);
      screen = 1;
  } else if (axpButton == PWR_BTN_SHORT_PRESS&&screen == 1) {
      M5.Axp.ScreenBreath (8);
      screen = 0;
  }
}
What I tried

I have tried various patterns, but I can press the power button briefly to reduce the screen brightness to 0, but I cannot press the power button briefly to increase the screen brightness to 8. I would appreciate it if you could give me some advice.

Supplementary information (FW/tool version, etc.)

Arduino IDE 1.8.13
M5stickC Plus
Windows 10

  • Answer # 1

    void loop () {
      int axpButton = M5.Axp.GetBtnPress ();
      if (axpButton == PWR_BTN_SHORT_PRESS) {
          M5.Axp.ScreenBreath (0);// If you press the power button briefly
          screen = 1;// All go through Kochi
      } else if (axpButton == PWR_BTN_SHORT_PRESS&&screen == 1) {
          M5.Axp.ScreenBreath (8);
          screen = 0;
      }
    }


    Correctly, for example:

    void loop () {
      int axpButton = M5.Axp.GetBtnPress ();
      if (axpButton == PWR_BTN_SHORT_PRESS) {// If you press the power button briefly ...
        if (screen == 1) {
          M5.Axp.ScreenBreath (8);
          screen = 0;
        } else {
          M5.Axp.ScreenBreath (0);
          screen = 1;
        }
    }

  • Answer # 2

    To explain in a little more detail

    if (axpButton == PWR_BTN_SHORT_PRESS) {

    Executes the contents of this if statement when axpButton is PWR_BTN_SHORT_PRESS. This sounds good?
    This means that the else statement that follows will be executed when axpButton is not PWR_BTN_SHORT_PRESS. However,

    } else if (axpButton == PWR_BTN_SHORT_PRESS&&screen == 1) {

    And, because the condition of axpButton == PWR_BTN_SHORT_PRESS has been added, the if statement here will not be executed.