Created
January 25, 2018 05:43
-
-
Save ccrome/eb6b67cd265ffdcc312f3b5d1bdac6ae to your computer and use it in GitHub Desktop.
How to run esp32 code on both cores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FreeRTOS.h" | |
#define LED1 14 | |
#define LED2 22 | |
TaskHandle_t Task1; | |
TaskHandle_t Task2; | |
void codeForTask1(void *parameter) | |
{ | |
while(1) | |
{ | |
Serial.print("This taks runs on core: "); | |
Serial.println(xPortGetCoreID()); | |
digitalWrite(LED1, HIGH); | |
delay(1000); | |
digitalWrite(LED1, LOW); | |
delay(1000); | |
} | |
} | |
void codeForTask2(void *parameter) | |
{ | |
while(1) | |
{ | |
Serial.print("This taks runs on core: "); | |
Serial.println(xPortGetCoreID()); | |
digitalWrite(LED2, HIGH); | |
delay(1000); | |
digitalWrite(LED2, LOW); | |
delay(1000); | |
} | |
} | |
void setup() { | |
Serial.begin(115200); | |
pinMode(LED1, OUTPUT); | |
pinMode(LED2, OUTPUT); | |
xTaskCreatePinnedToCore( | |
codeForTask1, | |
"Task_1", | |
1000, | |
NULL, | |
1, | |
&Task1, | |
1); | |
xTaskCreatePinnedToCore( | |
codeForTask2, | |
"Task_2", | |
1000, | |
NULL, | |
1, | |
&Task2, | |
0);// | |
} | |
void loop() { | |
delay(1); // include a delay to let the main loop idle. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment