/* Multitasking Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED1_PIN 2 // Assume LED1 is connected to pin 2
#define LED2_PIN 4 // Assume LED2 is connected to pin 4
void task1(void *pvParameters) {
(void)pvParameters;
for (;;) {
digitalWrite(LED1_PIN, HIGH); // Turn on LED1
vTaskDelay(pdMS_TO_TICKS(1000)); // Delay for 1 second
digitalWrite(LED1_PIN, LOW); // Turn off LED1
vTaskDelay(pdMS_TO_TICKS(1000)); // Delay for 1 second
}
}
void task2(void *pvParameters) {
(void)pvParameters;
for (;;) {
digitalWrite(LED2_PIN, HIGH); // Turn on LED2
vTaskDelay(pdMS_TO_TICKS(500)); // Delay for 500ms
digitalWrite(LED2_PIN, LOW); // Turn off LED2
vTaskDelay(pdMS_TO_TICKS(500)); // Delay for 500ms
}
}
void setup() {
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
xTaskCreatePinnedToCore(task1, "Task1", 1000, NULL, 1, NULL, APP_CPU_NUM);// Create tasks in the FreeRTOS environment on ESP32 and specify that the created task will run on a specific core of ESP32.
xTaskCreatePinnedToCore(task2, "Task2", 1000, NULL, 1, NULL, APP_CPU_NUM);
}
void loop() {
// Empty. No need for any code here.
}