Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- // Task handles
- TaskHandle_t Task1;
- TaskHandle_t Task2;
- // Task function for Core 0
- void Task0code(void *parameter) {
- while (true) {
- Serial.print("Task 0 is running on core ");
- Serial.println(xPortGetCoreID());
- delay(2000); // Simulate a slower background task
- }
- }
- // Task function for Core 1
- void Task1code(void *parameter) {
- while (true) {
- Serial.print("Task 1 is running on core ");
- Serial.println(xPortGetCoreID());
- delay(1000); // Simulate a faster real-time task
- }
- }
- void setup() {
- // Initialize Serial Monitor
- Serial.begin(115200);
- delay(1000); // Give Serial Monitor time to initialize
- Serial.println("Starting dual-core tasks...");
- // Create Task for Core 0
- xTaskCreatePinnedToCore(
- Task0code, // Task function
- "Task0", // Name of the task
- 10000, // Stack size in bytes
- NULL, // Parameter to pass to the task
- 1, // Task priority
- &Task1, // Task handle
- 0 // Core 0
- );
- // Create Task for Core 1
- xTaskCreatePinnedToCore(
- Task1code, // Task function
- "Task1", // Name of the task
- 10000, // Stack size in bytes
- NULL, // Parameter to pass to the task
- 1, // Task priority
- &Task2, // Task handle
- 1 // Core 1
- );
- }
- void loop() {
- // Main loop runs on Core 1 by default
- Serial.println("Loop task is running on core " + String(xPortGetCoreID()));
- delay(3000); // Simulate a general task in the loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement