ESP-IDF equivalent to Arduino delay()
You can use the FreeRTOS API to provide a delay similar to the Arduino delay()
function in the ESP-IDF framework. FreeRTOS is included in the PlatformIO ESP-IDF default configuration.
First, include the FreeRTOS headers
// Include FreeRTOS for delay
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
After that, you can use vTaskDelay(...)
to perform the delay. This example delays by 500ms
:
vTaskDelay(500 / portTICK_RATE_MS);
You can use vTaskDelay()
even if not using FreeRTOS tasks.
For a full example, refer to PlatformIO ESP-IDF ESP32 blink example