//#include <Arduino_FreeRTOS.h>
#define PIN_LED1 2
#define PIN_LED2 4
//NECESSÁRIO DECLARAR HANDLER para TASKS e OUTROS ARTIFÍCIOS NO FREERTOS
TaskHandle_t HandlePiscaLed1 = NULL;
TaskHandle_t HandlePiscaLed2 = NULL;
//DEFINO PROTÓTIPOS PARA FUNÇÕES QUE SERÂO TAREFAS A SEREM EXECUCATAS NO FREERTOS
//OU A PRÓPRIA FUNÇÃO PODE SER DECLARADA ANTES SETUP()
void TarefaLed1();
void TarefaLed2();
void setup() {
pinMode(PIN_LED1, OUTPUT);
pinMode(PIN_LED2, OUTPUT);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
xTaskCreatePinnedToCore(
TarefaLed1,
"piscarled1",
10000,
NULL,
1,
&HandlePiscaLed1,
1
);
xTaskCreatePinnedToCore(
TarefaLed2,
"piscarled2",
10000,
NULL,
1,
&HandlePiscaLed2,
0
);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void TarefaLed1(void *parameters){
while(true){
digitalWrite(PIN_LED1, HIGH);
Serial.println("BlinkTask: LED1 ON");
vTaskDelay(1000 / portTICK_PERIOD_MS); // 1000ms
digitalWrite(PIN_LED1, LOW);
Serial.println("BlinkTask: LED1 OFF");
vTaskDelay(1000 / portTICK_PERIOD_MS);
Serial.print("BlinkTask running on core ");
Serial.println(xPortGetCoreID());
}
}
void TarefaLed2(void *parameters){
while(true){
digitalWrite(PIN_LED2, HIGH);
Serial.println("BlinkTask: LED2 ON");
vTaskDelay(500 / portTICK_PERIOD_MS); // 1000ms
digitalWrite(PIN_LED2, LOW);
Serial.println("BlinkTask: LED2 OFF");
vTaskDelay(500 / portTICK_PERIOD_MS);
Serial.print("BlinkTask running on core! ");
Serial.println(xPortGetCoreID());
}
}