#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"// Se incluye el archivo de GPIOS, por si quieren utilizarlas.
#define LED_RED 5
#define LED_GREEN 2
#define LED_BLUE 4
xSemaphoreHandle mutuaExclusion;
//
void Led_Rojo (void *pvParameters) { // esta es mi primera tarea, siempre está dentro de un loop del que no sale nunca
// el planificador (scheduler), "el que reparte las cartas" me dice cuando se debe
// volver a entrar a esta tarea, va a depender de la prioridad
while(1) {
xSemaphoreTake(mutuaExclusion, portMAX_DELAY);
digitalWrite(LED_RED, HIGH);
xSemaphoreGive(mutuaExclusion);
xSemaphoreTake(mutuaExclusion, 500 / portTICK_PERIOD_MS);
digitalWrite(LED_RED, LOW);
}
}
void Led_Verde (void *pvParameters) {
while(1) {
xSemaphoreGive(mutuaExclusion);
digitalWrite(LED_GREEN, HIGH);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(LED_GREEN, LOW);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
//void Led_Azul (void *pvParameters) {
// while(1) {
// digitalWrite(LED_BLUE, HIGH);
// vTaskDelay(2000 / portTICK_PERIOD_MS);
// }
//}
void setup() {
pinMode(LED_RED, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
xTaskCreate(Led_Rojo, "Led_Rojo", 2000, NULL, tskIDLE_PRIORITY , NULL);// aquí si quieren pueden pueden utilizar directamente los números de prioridad
// o pueden incrementar tskIDLE_PRIORITY
xTaskCreate(Led_Verde, "Led_Verde", 2000, NULL, tskIDLE_PRIORITY , NULL);
mutuaExclusion = xSemaphoreCreateMutex();
//xTaskCreate(Led_Azul, "Led_Azul", 2000, NULL, tskIDLE_PRIORITY , NULL);
vTaskStartScheduler();
}
void loop() {}
//No hago nada