PowerOFF.ino 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Management 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.Lcd.setTextSize(2); // Set the font size. 设置字体大小
  22. M5.Lcd.print(
  23. "After 5 seconds, the program entered light sleep\n\n"); // Screen
  24. // printingformatted
  25. // string.
  26. // 输出格式化字符串
  27. delay(5000);
  28. M5.Power.lightSleep(
  29. SLEEP_SEC(5)); // Sleep for 5 seconds, then continue the program.
  30. // 睡眠5秒,结束后程序继续往下进行
  31. M5.Lcd.print(
  32. "press ButtonA: shutdown, use power button to turn back on"); // Screen
  33. // printingformatted
  34. // string.
  35. // 输出格式化字符串
  36. }
  37. /* After the program in setup() runs, it runs the program in loop()
  38. The loop() function is an infinite loop in which the program runs repeatedly
  39. 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
  40. loop()函数是一个死循环,其中的程序会不断的重复运行 */
  41. void loop() {
  42. M5.update(); // Read the press state of the key. 读取按键 A, B, C 的状态
  43. if (M5.BtnA.wasPressed()) { // Check if the key is pressed. 如果按键A被按下
  44. M5.Power.powerOFF(); // Turn off power. 关闭电源
  45. }
  46. }