Sleep.ino 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <M5Stack.h>
  2. void setup() {
  3. M5.begin();
  4. /*
  5. Power chip connected to gpio21, gpio22, I2C device
  6. Set battery charging voltage and current
  7. If used battery, please call this function in your project
  8. */
  9. M5.Power.begin();
  10. M5.Lcd.setBrightness(200);
  11. M5.Power.setWakeupButton(BUTTON_A_PIN);
  12. if(!M5.Power.canControl()) {
  13. M5.Lcd.printf("IP5306 is not i2c version\n");
  14. }
  15. }
  16. void loop() {
  17. M5.update();
  18. bool c=M5.Power.isResetbyPowerSW();
  19. bool d=M5.Power.isResetbyDeepsleep();
  20. M5.Lcd.printf("<<Sleep test>>\n");
  21. M5.Lcd.printf("power-on triggered at:%s%s\n\n",c?"POWER-SW":"",d?"DeepSleep-end":"");
  22. M5.Lcd.printf("Go lightSleep (5s or press buttonA wake up)\n");
  23. delay(2500);
  24. // Calling this function will disable the power button
  25. // To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
  26. M5.Power.lightSleep(SLEEP_SEC(5));
  27. M5.Lcd.printf("Go lightSleep (press buttonA wake up)\n");
  28. delay(2500);
  29. // Calling this function will disable the power button
  30. // To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
  31. M5.Power.lightSleep(0);
  32. M5.Lcd.printf("resume.\n\nGo deepSleep (press buttonA wake up) ");
  33. delay(2500);
  34. // Calling this function will disable the power button
  35. // To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
  36. M5.Power.deepSleep(0);
  37. }