#include "DHTesp.h"
#include "AsyncTimer.h"
DHTesp dht;
AsyncTimer timer1, timer2;
bool isLedOn = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dht.setup(14 , DHTesp::DHT22);
timer1.setInterval(readDHT,2000);
timer2.setInterval(led,1000);
pinMode(17, OUTPUT);
//digitalWrite(17,HIGH);
}
void loop() {
//เรียกฟังก์ชั่น
//readDHT();
timer1.handle();
timer2.handle();
delay(50);
}
void readDHT(){
float t = dht.getTemperature();
float h = dht.getHumidity();
Serial.print("Humidity = ");
Serial.print(h);
Serial.print(", Temperature = ");
Serial.println(t);
}
void led(){
isLedOn = !isLedOn;
digitalWrite(17,isLedOn);
// if(!isLedOn){
// digitalWrite(17, HIGH);
// isLedOn = true;
// }
// else{
// digitalWrite(17,LOW);
// isLedOn = false;
// }
}