ESP-IDF for Arduino Users, Tutorials Part 2: Delay
This is the second part of a series of ESP-IDF tutorials that I will complete as I learn stuff. Read part 1.
One of the best things about Arduino is the ability to just block for a period with:
delay(1000); // hang on a second, buddy
It’s also one of the worst things. As soon as you need to do a few things at the same time, you will end up using better systems, like calling millis() or using the elapsedMillis library.
Anyway, the IDF has you covered. You can delay, but amazingly it appears that once you multi-task (which you will with Free RTOS), the delay doesn’t block the other tasks from running.
My Notes:
- Read the docs, now or later
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
- Delay doesn’t have to block like Arduino.
- Delay some milliseconds like this:
vTaskDelay(pdMS_TO_TICKS(10));
Since vTaskDelay accepts ticks, the pdMS_TO_TICKS macro will convert for you.
Help yourself out by adding your own macros if you are lazy. I am lazy.
#define DELAY(ms) vTaskDelay(pdMS_TO_TICKS(ms))#define DELAY_1S DELAY(1000)