ESP32: ESP32_xQueue.ino

File ESP32_xQueue.ino, 1.0 KB (added by krit, 3 years ago)
Line 
1#include<Arduino.h>
2# To make it work, we need to
3# 1. change Line 34 & 35 to increase stack from 1024 to 1500
4# 2. change Line 24 Queue size from 10 to 50
5
6
7QueueHandle_t     qu_task;
8TaskHandle_t xHandle = NULL;
9
10void vGetQueueTask(void *pvParameters){
11  int getvalue = 0;
12  while(true){
13    if (xQueueReceive(qu_task, &getvalue, 0)) {
14       Serial.println("Queue get: " + String(getvalue));
15    }
16    vTaskDelay(2000 / portTICK_PERIOD_MS);
17  }
18}
19void vPutQueueTask(void * pvParameters){
20   int value = 0;
21   while(true){
22       xQueueSend(qu_task, &value, 0);
23       Serial.println("Queue put: " + String(value));
24       if (value == 10) {
25         break;
26       }
27       value++;
28       vTaskDelay(500 / portTICK_PERIOD_MS);
29   }
30   vTaskDelete(xHandle);
31}
32
33void setup() {
34  Serial.begin(115200);
35  qu_task = xQueueCreate(10, sizeof(int));
36  xTaskCreate(vGetQueueTask, "vGetQueueTask", 1024, NULL, tskIDLE_PRIORITY - 1, NULL);
37  xTaskCreate(vPutQueueTask, "vPutQueueTask", 1024, NULL, tskIDLE_PRIORITY - 2, &xHandle);
38}
39
40void loop() {}