#define PINO_LED 2
QueueHandle_t estadoLED;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode (PINO_LED, OUTPUT);
estadoLED = xQueueCreate(1, sizeof(int)); // definir qtde de elementos em bytes da fila
xTaskCreatePinnedToCore(
ledBlink, // funçao da tarefa
"led Blink", // string da tarefa
1000, // tamanho da pilha
NULL, // parametro a ser passado
1, // prioridade da terefa
NULL, // identificador ou handler da terefa
0 // núcleo onde será executado a tarefa
);
xTaskCreatePinnedToCore(
printEstado, // funçao da tarefa
"printEstado", // string da tarefa
1000, // tamanho da pilha
NULL, // parametro a ser passado
2, // prioridade da terefa
NULL, // identificador ou handler da terefa
0 // núcleo onde será executado a tarefa
);
}
void loop() {
// put your main code here, to run repeatedly:
}
void ledBlink(void *parametro){
while(true){
digitalWrite(PINO_LED, !digitalRead(PINO_LED));
int stLED = digitalRead(PINO_LED);
xQueueSend(estadoLED, &stLED, 100);
vTaskDelay(500/portTICK_PERIOD_MS);// PUSAR A TAREFA
}
}
void printEstado (void *parametro){
int rcvLED;// estado do led foi recebido
while(true){
if (xQueueReceive(estadoLED, &rcvLED, 500)){
if(rcvLED == 1) Serial.println("LED ligado!");
else Serial.println("LED Desligado!");
}
}
}