Sleep.ino 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. *******************************************************************************
  3. *Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. * Visit for more information: https://docs.m5stack.com/en/core/gray
  7. * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
  8. *
  9. * Describe: Power example. 电源管理示例
  10. * Date: 2021/7/21
  11. *******************************************************************************
  12. */
  13. #include <M5Stack.h>
  14. /* After M5Core is started or reset
  15. the program in the setUp () function will be run, and this part will only be run
  16. once. 在 M5Core
  17. 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
  18. void setup() {
  19. M5.begin(); // Init M5Core. 初始化 M5Core
  20. M5.Power.begin(); // Init Power module. 初始化电源模块
  21. M5.Power.setWakeupButton(BUTTON_A_PIN); // Set the screen wake-up button to
  22. // A. 将屏幕唤醒的按键设置为A
  23. M5.Lcd.setBrightness(
  24. 200); // Set the screen brightness to 200 nits. 设置屏幕亮度为200尼特
  25. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  26. }
  27. /* After the program in setup() runs, it runs the program in loop()
  28. The loop() function is an infinite loop in which the program runs repeatedly
  29. 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
  30. loop()函数是一个死循环,其中的程序会不断的重复运行 */
  31. void loop() {
  32. M5.update(); // Read the press state of the key. 读取按键 A, B, C 的状态
  33. bool c =
  34. M5.Power
  35. .isResetbyPowerSW(); // Determine if M5Core is started when powered
  36. // on. 确定M5Core是否在接通电源时启动
  37. bool d =
  38. M5.Power.isResetbyDeepsleep(); // Determine if M5Core starts after deep
  39. // sleep. 确定M5Core是否在深度睡眠后启动
  40. M5.Lcd.println(
  41. "<Sleep test>"); // The screen prints the formatted string and wraps
  42. // the line. 输出格式化字符串并换行
  43. M5.Lcd.printf("power-on triggered at:%s%s\n\n", (c) ? ("POWER-SW") : (""),
  44. (d) ? ("DeepSleep-end") : (""));
  45. M5.Lcd.printf("Go lightSleep (5s or press buttonA wake up)\n");
  46. delay(5000); // delay 5000ms. 延迟5000ms
  47. /*Restart after 10 seconds of light sleep and continue from the next line
  48. Calling this function power button will disable the power button to restore
  49. Please call M5.Power.setPowerBoostKeepOn(false)*/
  50. /*轻度睡眠10秒后重新启动,程序从下一行继续执行
  51. 调用此函数将禁用电源按钮,要恢复电源按钮
  52. 请调用M5.Power.setPowerBoostKeepOn(false)*/
  53. M5.Power.lightSleep(SLEEP_SEC(10));
  54. M5.Lcd.printf("Go lightSleep (press buttonA wake up)\n");
  55. delay(5000);
  56. M5.Power.lightSleep(0);
  57. M5.Lcd.printf("resume.\n\nGo deepSleep (press buttonA wake up) ");
  58. delay(5000);
  59. /*After waking up from deep sleep for 0 seconds, the CPU will restart and
  60. the program will be executed from the beginning
  61. Calling this function will disable the power button to restore the power
  62. button Please call M5.Power.setPowerBoostKeepOn(false)*/
  63. /*深度睡眠0秒后唤醒,CPU将重新启动,程序将从头开始执行
  64. 调用此函数将禁用电源按钮,要恢复电源按钮
  65. 请调用M5.Power.setPowerBoostKeepOn(false)*/
  66. M5.Power.deepSleep(0);
  67. }