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
freertos_includes.cpp
// 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:
delay_example.cpp
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
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