#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define POT_1_PIN 4 // Pin analógico para el primer potenciómetro
#define POT_2_PIN 2 // Pin analógico para el segundo potenciómetro
#define LED_PIN 25 // Pin del LED
void readPot1Task(void *pvParameters) {
pinMode(POT_1_PIN, INPUT);
while (1) {
int potValue1 = analogRead(POT_1_PIN);
Serial.print("Potenciómetro 1: ");
Serial.println(potValue1);
vTaskDelay(pdMS_TO_TICKS(500)); // Actualización cada 500 ms
}
}
void controlBrightnessTask(void *pvParameters) {
pinMode(POT_2_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
while (1) {
int potValue2 = analogRead(POT_2_PIN);
int brightness = map(potValue2, 0, 4095, 0, 255); // Mapeo del valor del potenciómetro al brillo del LED
analogWrite(LED_PIN, brightness);
vTaskDelay(pdMS_TO_TICKS(100)); // Pequeña espera antes de la próxima actualización
}
}
void setup() {
Serial.begin(115200);
xTaskCreate(readPot1Task, "readPot1Task", 2048, NULL, 1, NULL);
xTaskCreate(controlBrightnessTask, "controlBrightnessTask", 2048, NULL, 1, NULL);
}
void loop() {
// No es necesario tener código aquí si se usan tareas con FreeRTOS
}