#include "DHT.h"
#include <LiquidCrystal.h>
#include <Arduino_FreeRTOS.h>
#include <queue.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
//#define DHTTYPE DHT11
//#define DHTTYPE DHT21
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
QueueHandle_t xQueue;
void DHTTask( void *pvParameters );
void LcdTask( void *pvParameters );
void setup() {
Serial.begin(9600);
dht.begin();
lcd.begin(16,2);
lcd.print("hello world");
//xQueue = xQueueCreate( 5, sizeof( int ) );
//if( xQueue != NULL )
{
xTaskCreate(
DHTTask,
"task1",
128,
NULL,
2,
NULL );
/*xTaskCreate(
LcdTask,
"Receiver",
128,
NULL,
1,
NULL );*/
vTaskStartScheduler();
}
}
void loop()
{
// put your main code here, to run repeatedly:
}
void DHTTask(void *pvParameters)
{
while(1)
{
float t = dht.readTemperature();
//xQueueSend( xQueue, &t, portMAX_DELAY ==pdPASS);
//vTaskDelay(100);
if (isnan(t)) {
lcd.print(F("Failed to read from DHT sensor!"));
return;
}
lcd.clear();
lcd.setCursor(0,0); lcd.print("TEMP: ");
lcd.print(t);
Serial.print( "Nhiet do = ");
Serial.println(t);
}
}
/*void LcdTask( void *pvParameters )
{
while(1)
{
float ReceivedValue;
if (xQueueReceive( xQueue, &ReceivedValue, portMAX_DELAY ) == pdPASS)
{
Serial.print( "Nhiet do = ");
Serial.println(ReceivedValue);
lcd.clear();
lcd.setCursor(0,0); lcd.print("TEMP: ");
lcd.print(ReceivedValue);
}
taskYIELD();
}
}*/