#include <Arduino_FreeRTOS.h>
#include <task.h>
struct TaskConfig{
const char* name;
unsigned long period;
unsigned long execTime;
TaskHandle_t handle;
};
TaskConfig tasks[]{
{"tache 1",50, 20, NULL},
{"tache 2",100, 25, NULL},
{"tache 3",200, 50, NULL}
};
const int numTasks = sizeof(tasks) / sizeof(tasks[0]);
void taskFunction(void *pvParameters) {
TaskConfig* task = (TaskConfig*) pvParameters;
unsigned long last_run_time = 0;
while (1){
unsigned long current_time = millis();
if(current_time - last_run_time >= task->period){
Serial.print(task ->name);
Serial.print(" exécutée à ");
Serial.print(current_time);
Serial.println(" ms");
last_run_time = current_time;
vTaskDelay(task->execTime / portTICK-PERIOD_MS)
}
vTaskDelay(1);
}
}
void setup() {
Serial.begin(9600);
Serial.println("Démarrage du système temps réel avec FreeRTOS...");
for (int i =0; i< numTasks; i++) {
xTaskCreate(taskFunction, tasks[i].name, 128, &tasks[i], i+1, &tasks[i].handle);
}
}
void loop() {
delay(1000);
}