#include <Arduino_FreeRTOS.h>
#include <task.h>
void task1(void * parameter) {
int CurrentTickCount = 0;
int PreviousTickCount = 0;
int Period = 0;
while (1) {
CurrentTickCount = xTaskGetTickCount(); // Get the current tick count
Period = pdTICKS_TO_MS(CurrentTickCount) - pdTICKS_TO_MS(PreviousTickCount); // Calculate period
Serial.print("Period 01 = ");
Serial.println(Period); // Print the period
PreviousTickCount = CurrentTickCount; // Update the previous tick count
vTaskDelay(pdMS_TO_TICKS(400)); // Delay for 400ms
}
}
void task2(void * parameter) {
int CurrentTickCount = 0;
int PreviousTickCount = 0;
int Period = 0;
while (1) {
CurrentTickCount = xTaskGetTickCount(); // Get the current tick count
Period = pdTICKS_TO_MS(CurrentTickCount) - pdTICKS_TO_MS(PreviousTickCount); // Calculate period
Serial.print("Period 02 = ");
Serial.println(Period); // Print the period
PreviousTickCount = CurrentTickCount; // Update the previous tick count
vTaskDelay(pdMS_TO_TICKS(400)); // Delay for 400ms
}
}
void setup() {
// Setup code here, runs once
Serial.begin(9600);
// Create two tasks
xTaskCreate(task1, "Task1", 128, NULL, 1, NULL);
xTaskCreate(task2, "Task2", 128, NULL, 1, NULL);
// Start the scheduler
vTaskStartScheduler();
}
void loop() {
// Empty loop since FreeRTOS tasks handle the logic
}