typedef struct {
byte deviceID;
int value1;
int value2;
} SENSOR;
QueueHandle_t xQueue = xQueueCreate(8, sizeof(SENSOR));
void sensorA (void *pvParam) {
SENSOR sensorA;
sensorA.deviceID = 1;
while (1) {
while (sensorA.value1 >= 255||sensorA.value2>=255)
sensorA.value1=sensorA.value2 = 0;
sensorA.value1++;
sensorA.value2++;
TickType_t timeOut = 2000;
if (xQueueSend(xQueue, &sensorA, timeOut) != pdPASS) {
Serial.println("DHT22: Queue is full.");
}
}
vTaskDelay(1000);
}
void Display (void *pvParam) {
SENSOR data;
TickType_t timeOut = 2000;
if (xQueueReceive(xQueue, &data, timeOut) == pdPASS) {
// Serial.println(String(data.deviceID));
// Serial.println(String(data.value1));
// Serial.println(String(data.value2));
Serial.println(data.deviceID);
Serial.println(data.value1);
Serial.println(data.value2);
} else {
Serial.println("LCD: Message Queue is Empty");
};
vTaskDelay(1000);
}
void setup()
{
Serial.begin(115200);
xTaskCreatePinnedToCore(sensorA, "User A", 1024 , NULL, 1, NULL,1);
// xTaskCreate(sensorB, "User B", 1024 * 8, NULL, 1, NULL);
xTaskCreatePinnedToCore(Display, "Display", 1024 , NULL, 1, NULL,1);
}
void loop() {}