#include <LiquidCrystal.h>
#include <Servo.h>
#include "DHT.h"
#define DHTPIN A0 // 连接到dht传感器的数字引脚
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
Servo myservo;
const float BETA = 3950;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int pushButton=digitalRead(2);
int potpin=1,val;
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
myservo.attach(3);
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
pushButton=digitalRead(2);
if(pushButton==LOW){
delay(45);
if(pushButton==LOW){
lcd.print(t);
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.print("\n");
delay(100);
}
}
else if(pushButton==HIGH){
delay(45);
if(pushButton==HIGH){
lcd.print(f);
Serial.print(f);
Serial.print(F("°F"));
Serial.print("\n");
delay(100);
}
}
lcd.clear();
val=analogRead(potpin);
val=map(val,0,1023,0,180);
myservo.write(val);
delay(15);
pushButton=0;
}