#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Arduino_FreeRTOS.h>
#include <task.h>
// Define pins
#define TFT_CS 10
#define TFT_DC 8
#define TFT_RST 9
// Initialize display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Task to update and display the counter
void displayCounterTask(void *pvParameters) {
(void) pvParameters; // Unused parameter
uint32_t counter = 0;
while (1) {
// Clear and display the counter
tft.setCursor(10, 10);
tft.print("Counter: ");
tft.println(counter);
// Increment the counter
counter++;
// Delay for 1 second (FreeRTOS delay)
vTaskDelay(pdMS_TO_TICKS(1000)); // Convert milliseconds to ticks
}
}
// Task to update and display the counter
void displayCounter2Task(void *pvParameters) {
(void) pvParameters; // Unused parameter
uint32_t counter = 0;
while (1) {
// Clear and display the counter
tft.setCursor(10, 100);
tft.print("Counter: ");
tft.println(counter);
// Increment the counter
counter++;
// Delay for 2 seconds (FreeRTOS delay)
vTaskDelay(pdMS_TO_TICKS(2000)); // Convert milliseconds to ticks
}
}
void setup() {
// Initialize the display
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 10);
tft.println("Initializing...");
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); // Black background for overwriting
// Create the FreeRTOS tasks
xTaskCreate(
displayCounterTask, // Task function
"CounterTask", // Task name
512, // Stack size in words
NULL, // Task parameters
1, // Task priority
NULL // Task handle
);
xTaskCreate(
displayCounter2Task, // Task function
"Counter2Task", // Task name
512, // Stack size in words
NULL, // Task parameters
1, // Task priority
NULL // Task handle
);
// Start the FreeRTOS scheduler
vTaskStartScheduler();
}
void loop() {
// Nothing to do here
}