code
نسخ
اقتباس
عرض
تنزيل
/*Use ESP32 Dual Core*/
int x=0;
TaskHandle_t Task1_hx711;
TaskHandle_t Task2_rfid;
void setup() {
Serial.begin(9600);
//create a task that will be executed in the Task1_function_example() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1_function_example, /* Task function. */
"Task1_hx711", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task ===> on this core */
&Task1_hx711, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
//create a task that will be executed in the Task2_function_example() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
Task2_function_example, /* Task function. */
"Task2_rfid", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task ===> on this core */
&Task2_rfid, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(500);
}
void loop() {
Serial.println("==================("+String(x)+")===================");
delay(500);
}
//Task1_function_example:
void Task1_function_example( void * pvParameters )
{
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
while(1)
{
x=x+1;
delay(250);
}
}
//Task2_function_example:
void Task2_function_example( void * pvParameters )
{
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
while(1)
{
x=x+1000;
delay(1000);
}
}