#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
while (!Serial) {}
// Now set up two tasks to run independently.
xTaskCreate( TaskBlink, "Blink", 1024, NULL, 1, NULL);
xTaskCreate( TaskAnalogRead, "AnalogRead", 1024, NULL, 1, NULL);
}
void loop() {}
/*---------------------- Tasks ---------------------*/
void TaskBlink( void *pvParameters ) // This is a task.
{
// initialize digital LED_BUILTIN on pin 13 as an output.
pinMode(2, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 1000 ); // wait for one second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 1000 ); // wait for one second
}
}
void TaskAnalogRead(void *pvParameters) // This is a task.
{
int potPin = 12;
for (;;)
{
// read the input on analog pin 12:
int sensorValue = analogRead(potPin);
// print out the value you read:
Serial.println(sensorValue);
vTaskDelay( 100 ); // one tick delay (100ms) in between reads for stability
}
}