特定时间的深度睡眠

Deep sleep for a specific time

我需要在特定时间激活外设,然后休眠一段时间,然后再次停用外设。

我可以用一个简单的 sleep 来做到这一点,但这会使我的 ESP32 保持清醒并烧毁电池。有没有办法让深度睡眠达到要求的时间,然后再醒来?

理想情况下,我会简单地安排 运行 在一定时间后停用程序。

最好的方法是什么?

Toit 有 following example 让 ESP32 进入深度睡眠 10 秒的功能。

// Copyright (C) 2021 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the examples/LICENSE file.

import esp32

main:
  run_time ::= Duration --us=esp32.total_run_time
  sleep_time ::= Duration --us=esp32.total_deep_sleep_time
  print "Awake for $(run_time - sleep_time) so far"
  print "Slept for $sleep_time so far"
  esp32.deep_sleep (Duration --s=10)