This project is implemented using various tasks. Task's handle are also used in this design to suspend a ongoing task or to resume a suspended task.
There are nine LEDs in this project. I have created three tasks (one for Red LEDs, one for Blue LEDs and one for Green LEDs) to control all nine LEDs. The music produced is with the help of an active buzzer for which I created a separate task.
Task to create music is:
xTaskCreate(song, "buzzer song", 100, NULL, 1, NULL);
In this task I have not passed any parameters and task handle is also not required.
Red LEDs task is:
void RedLEDPattern(void *pvParameter)
{
while (1)
{
eventcount++;
for (int i = 0; i < 3; i++)
{
digitalWrite(RedLEDs[i], digitalRead(RedLEDs[i])^1);
if (eventcount >= 15000)
{
resumecount = true;
eventcountresume = 0;
vTaskSuspend(Greencontrol);
vTaskSuspend(NULL);
}
}
}
}
In this task Green LEDs task is suspended using it's task handler. In this task after suspending green LEDs task, this task suspends itself also. For suspending a task itself, task handler is not required as we can see in the above code, NULL is used in place of task handler. Now after some time we will resume both these tasks in blue LEDs task.
Blue LEDs task is:
void BlueLEDPattern(void *pvParameter)
{
while (1)
{
for (int i = 0; i < 3; i++)
{
if (eventcount >= 15000)
{
digitalWrite(BlueLEDs[i], HIGH);
}
}
if(resumecount == true)
{
eventcountresume++;
if(eventcountresume >= 15000)
{
eventcount = 0;
resumecount = false;
for (int i = 0; i < 3; i++)
{
digitalWrite(BlueLEDs[i], LOW);
}
vTaskResume(Redcontrol);
vTaskResume(Greencontrol);
}
}
}
}
In this task, both the Red LEDs and Green LEDs tasks are resumed which were suspended before using there respective task handlers.
This project is made for the understanding of FreeRTOS. It depicts how a task can be suspended and resumed using task handlers. FreeRTOS is real time operating system designed for embedded devices. Coding is done on visual studio using platformIO extension.
Comments
Please log in or sign up to comment.