29 lines
639 B
C++
29 lines
639 B
C++
#include "DHT11control.h"
|
|
|
|
void setup() {
|
|
// 初始化串口通信
|
|
Serial.begin(115200);
|
|
// 启动DHT传感器
|
|
dht.begin();
|
|
}
|
|
|
|
void loop() {
|
|
// 获取温湿度数据指针
|
|
float* results = getTempAndHumidity();
|
|
|
|
// 数据有效性校验
|
|
if(results[0] != -999 && results[1] != -999) {
|
|
// 格式化输出温度数据
|
|
Serial.print("Temperature: ");
|
|
Serial.print(results[0]);
|
|
Serial.print(" °C, ");
|
|
|
|
// 格式化输出湿度数据
|
|
Serial.print("Humidity: ");
|
|
Serial.print(results[1]);
|
|
Serial.println(" %");
|
|
}
|
|
|
|
// 维持2秒采样间隔
|
|
delay(2000);
|
|
} |