ESP-IDF 中 Arduino delay() 的等效方法
你可以使用 FreeRTOS API 在 ESP-IDF 框架中提供类似 Arduino delay() 函数的延迟。FreeRTOS 包含在 PlatformIO ESP-IDF 默认配置中。
首先,包含 FreeRTOS 头文件
freertos_includes.cpp
// 包含 FreeRTOS 用于延迟
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>之后,你可以使用 vTaskDelay(...) 执行延迟。此示例延迟 500ms:
delay_example.cpp
vTaskDelay(500 / portTICK_RATE_MS);即使不使用 FreeRTOS 任务,你也可以使用 vTaskDelay()。
完整示例请参见PlatformIO ESP-IDF ESP32 blink 示例
Check out similar posts by category:
C/C++, Embedded, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow