#define LED_GREEN GPIO_NUM_5
#define LED_YELLOW GPIO_NUM_6
#define LED_RED GPIO_NUM_7
#define LED_BLUE GPIO_NUM_8
/* The task functions. */
void vContinuousProcessingTask1( void *pvParameters );
void vContinuousProcessingTask2( void *pvParameters );
void vContinuousProcessingTask3( void *pvParameters );
void vPeriodicTask( void *pvParameters );
/* Define the strings that wi ll be passed in as the task parameters. These are
defined const and off the stack to ensure they remain valid when the tasks are
executing. */
const char *pcTextForTask1 = "Continuous task 1 running\r\n";
const char *pcTextForTask2 = "Continuous task 2 running\r\n";
const char *pcTextForTask3 = "Continuous task 3 running\r\n";
const char *pcTextForPeriodicTask = "Periodic task is running\r\n";
/*-----------------------------------------------------------*/
void setup( void )
{
Serial.begin(9600);
pinMode(LED_GREEN,OUTPUT);
pinMode(LED_YELLOW, OUTPUT);
pinMode(LED_RED, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_GREEN|LED_YELLOW|LED_RED, LOW);
/* Create two non-blocking tasks. */
xTaskCreate( vContinuousProcessingTask1, "Task 1", 2000, (void*)pcTextForTask1, 1, NULL );
xTaskCreate( vContinuousProcessingTask2, "Task 2", 2000, (void*)pcTextForTask2, 1, NULL );
xTaskCreate( vContinuousProcessingTask3, "Task 3", 2000, (void*)pcTextForTask3, 1, NULL );
/* Create one instance of the periodic task at priority 2. */
xTaskCreate( vPeriodicTask, "Task 3", 2000, (void*)pcTextForPeriodicTask, 2, NULL);
/* If all is well we will never reach here as the scheduler will now be
running. If we do reach here then it is likely that there was insufficient
heap available for the idle task to be created. */
for( ;; );
// return 0;
}
/*-----------------------------------------------------------*/
void vContinuousProcessingTask1( void *pvParameters )
{
char *pcTaskName;
/* The string to print out is passed in via the parameter. Cast this to a
character pointer. */
pcTaskName = ( char * ) pvParameters;
/* As per most tasks, this task is implemented in an infinite loop. */
for( ;; )
{
/* Print out the name of this task. This task just does this repeatedly
without ever blocking or delaying. */
Serial.print( pcTaskName );
digitalWrite(LED_GREEN,!digitalRead(LED_GREEN));
delay(1000);
}
}
/*-----------------------------------------------------------*/
void vContinuousProcessingTask2( void *pvParameters )
{
char *pcTaskName;
/* The string to print out is passed in via the parameter. Cast this to a
character pointer. */
pcTaskName = ( char * ) pvParameters;
/* As per most tasks, this task is implemented in an infinite loop. */
for( ;; )
{
/* Print out the name of this task. This task just does this repeatedly
without ever blocking or delaying. */
Serial.print( pcTaskName );
digitalWrite(LED_YELLOW,!digitalRead(LED_YELLOW));
delay(500);
}
}
/*-----------------------------------------------------------*/
void vContinuousProcessingTask3( void *pvParameters )
{
char *pcTaskName;
/* The string to print out is passed in via the parameter. Cast this to a
character pointer. */
pcTaskName = ( char * ) pvParameters;
/* As per most tasks, this task is implemented in an infinite loop. */
for( ;; )
{
/* Print out the name of this task. This task just does this repeatedly
without ever blocking or delaying. */
Serial.print( pcTaskName );
digitalWrite(LED_BLUE,!digitalRead(LED_BLUE));
delay(500);
}
}
/*-----------------------------------------------------------*/
void vPeriodicTask( void *pvParameters )
{
TickType_t xLastWakeTime;
char *pcTaskName;
/* The xLastWakeTime variable needs to be initialized with the current tick
count. Note that this is the only time we access this variable. From this
point on xLastWakeTime is managed automatically by the vTaskDelayUntil()
API function. */
xLastWakeTime = xTaskGetTickCount();
pcTaskName = ( char * ) pvParameters;
/* As per most tasks, this task is implemented in an infinite loop. */
for( ;; )
{
/* Print out the name of this task. */
Serial.print( pcTaskName );
digitalWrite(LED_RED,!digitalRead(LED_RED));
/* We want this task to execute exactly every 500 milliseconds. */
vTaskDelayUntil( &xLastWakeTime, (5000 / portTICK_PERIOD_MS ) );
}
}
//------------------------------------------------------------------------------
void loop() {}