In the earlier example, we created 2 high priority task and an Idle task.
In this tutorial, we will see how to use the scheduler Idle task to run the user function.

What is Idle Task

Idle task is automatically created when the scheduler starts.
When no tasks are available for the CPU then this task will run.
When a task is deleted, the memory used by it will not be free immediately. This will be done in the idle task.

Using Idle Task Hook

To use the Idle task, configUSE_IDLE_HOOK should be set to 1.
In Arduino the loop() function is hooked to freeRtos Idle Task and will be called whenever the scheduler runs its Idle Task.

Example

Output

TaskIdleHook.jpg