#include "DHT.h"
#define DHTPIN 13
#define DHTTYPE DHT11
const int led = 2;
DHT dht(DHTPIN, DHTTYPE);
setup() {
Serial.begin(115200);
pinMode(led,OUTPUT);
dht.begin();
xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, NULL, 1);
delay(500);
xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, NULL, 0);
delay(500);
}
void Task1code(void * pvParameters ){
Serial.print("Task1 在核心上运行");
Serial.println(xPortGetCoreID());
for(;;){
digitalWrite(led, HIGH);
delay(300);
digitalWrite(led,LOW);
delay(300);
}
}
void Task2code(void * pvParameters ){
Serial.print("Task2 在核心上运行");
Serial.println(xPortGetCoreID());
for(;;){
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
Serial.print("温度:");
Serial.print(t);
Serial.print(" *C \n ");
if (isNan(h) || isNan(t) || isNan(f)) {
Serial.println("读取 DHT 传感器失败!");
return;
}
delay(2000);
}
}
loop() {
}
欢迎联系本站长QQ:3216572