research: testing with multitask and add samples
This commit is contained in:
parent
29b33da68a
commit
605fa823c6
76
esp32/multiTaskTesting.h
Normal file
76
esp32/multiTaskTesting.h
Normal file
@ -0,0 +1,76 @@
|
||||
TaskHandle_t Task1;
|
||||
TaskHandle_t Task2;
|
||||
const int led1 = 2;
|
||||
const int led2 = 4;
|
||||
|
||||
void stp(){
|
||||
pinMode(led1, OUTPUT);
|
||||
pinMode(led2, OUTPUT);
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
Task1code, /* Task function. */
|
||||
"Task1", /* name of task. */
|
||||
10000, /* Stack size of task */
|
||||
NULL, /* parameter of the task */
|
||||
1, /* priority of the task */
|
||||
&Task1, /* Task handle to keep track of created task */
|
||||
0); /* pin task to core 0 */
|
||||
// xTaskCreate(Task1code, "task1", 1000, NULL, 1, NULL);
|
||||
delay(500);
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
Task2code, /* Task function. */
|
||||
"Task2", /* name of task. */
|
||||
10000, /* Stack size of task */
|
||||
NULL, /* parameter of the task */
|
||||
1, /* priority of the task */
|
||||
&Task2, /* Task handle to keep track of created task */
|
||||
1); /* pin task to core 1 */
|
||||
// xTaskCreate(Task2code, "task2", 1000, NULL, 1, NULL);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
//Task1code: blinks an LED every 1000 ms
|
||||
void Task1code( void * pvParameters ){
|
||||
Serial.print("Task1 running on core ");
|
||||
Serial.println(xPortGetCoreID());
|
||||
|
||||
for(;;){
|
||||
digitalWrite(led1, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(led1, LOW);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
//Task2code: blinks an LED every 700 ms
|
||||
void Task2code( void * pvParameters ){
|
||||
Serial.print("Task2 running on core ");
|
||||
Serial.println(xPortGetCoreID());
|
||||
|
||||
for(;;){
|
||||
digitalWrite(led2, HIGH);
|
||||
delay(700);
|
||||
if(!s.isFired){
|
||||
digitalWrite(led2, LOW);
|
||||
delay(700);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void killOne(){
|
||||
// Kill task1 if it's running
|
||||
if(Task1 != NULL) {
|
||||
eTaskState taskState= eTaskGetState(Task1 );
|
||||
if(taskState == eDeleted){
|
||||
Serial.println("Task deleted");
|
||||
}else{
|
||||
Serial.println("No more green");
|
||||
vTaskDelete(Task1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user