ESP32: ESP32_xTaskDelete.ino

File ESP32_xTaskDelete.ino, 759 bytes (added by krit, 3 years ago)
Line 
1#include <Arduino.h>
2
3#define LED1  15
4#define LED2  17
5
6TaskHandle_t xHandle_1 = NULL;
7
8void vBlink1Task(void * pvParameters){
9  while(true){
10    digitalWrite(LED1, !digitalRead(LED1));
11    vTaskDelay(1000 / portTICK_PERIOD_MS);
12  }
13}
14
15void vBlink2Task(void *pvParameters){
16  int n = 0;
17  while(true){
18    digitalWrite(LED2, !digitalRead(LED2));
19    vTaskDelay(100 / portTICK_PERIOD_MS);
20    if(n++ > 50) {
21      digitalWrite(LED2, LOW);
22      vTaskDelete( xHandle_1 );
23    }
24  }
25}
26
27void setup() {
28  Serial.begin(115200);
29  pinMode(LED1, OUTPUT);
30  pinMode(LED2, OUTPUT);
31  xTaskCreate(vBlink1Task, "vBlink1Task", 1024, NULL, tskIDLE_PRIORITY, NULL);
32  xTaskCreate(vBlink2Task, "vBlink2Task", 1024, NULL, tskIDLE_PRIORITY+1, &xHandle_1);
33
34}
35
36void loop() { }