Arduino学习笔记:FreeRTOS——ESP32多任务处理
Demo
TaskHandle_t TASK_HandleOne = NULL;
TaskHandle_t TASK_HandleTwo = NULL;
void setup() {
Serial.begin(115200);
delay(1000);
int num = 0;
xTaskCreate(
TASK_ONE,
"TaskOne",
8*1024,
NULL,
1,
&TASK_HandleOne);
xTaskCreate(
TASK_TWO,
"TaskTwo",
8*1024,
(void *)&num,
1,
&TASK_HandleTwo);
}
void loop() {
delay(1000);
Serial.println("Hell from Main~");
}
void TASK_ONE(void *param )
{
for( int i = 0;i<10;i++ )
{
Serial.println("Hello from TaskOne~");
delay(1000);
}
Serial.println("Ending TaskOne!");
vTaskDelete( TASK_HandleOne );
}
void TASK_TWO(void *param )
{
int *pNum = (int *)param;
for( int i = 0;i<10;i++ )
{
*pNum = i;
Serial.println((*pNum));
Serial.println("Hello from TaskTwo~~");
delay(1000);
}
Serial.println("Ending TaskTwo!!");
vTaskDelete( TASK_HandleTwo );
}
串口打印结果
|