#define LED_PIN 2
// Task Handle
TaskHandle_t ledTaskHandle = NULL;
void ledTask(void *pvParameters){
//Retrieve the core number the task is running on
int core = xPortGetCoreID();
for (;;){
//Toggle the LED
digitalWrite(LED_PIN, HIGH);
Serial.printf("LED ON Running on core %d\n", core);
vTaskDelay(1000 / portTICK_PERIOD_MS);
digitalWrite(LED_PIN, LOW);
Serial.printf("LED OFF Running on core %d\n", core);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
//Create the LED task
xTaskCreatePinnedToCore(
ledTask, //Task Function
"LED Task", //Task Name
2048, //Stack Size
NULL, //Task Parameters
1, //Task Priority
&ledTaskHandle, //Task Handle
1 //Core Number to run the task on (0 or 1)
);
}
void loop() {
// // put your main code here, to run repeatedly:
// digitalWrite(LED_PIN, HIGH);
// Serial.println("LED ON");
// delay(1000); // this speeds up the simulation
// digitalWrite(LED_PIN, LOW);
// Serial.println("LED OFF");
// delay(1000);
}