#include "DHT.h"
#include <Servo.h>

Servo myservo;

#define DHTPIN 2     
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

int tempservo = 0;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
  myservo.attach(11);
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Check if any reads failed and exit early (to try again).
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //tempservo map(temperature, -40, 80, 0, 180);
  tempservo = map(temperature, 10, 40, 0, 180);
  myservo.write(tempservo);



  Serial.print("Feuchtigkeit: ");
  Serial.print(humidity);
  Serial.print("% ");
  Serial.print("Temperatur: ");
  Serial.print(temperature);
  Serial.println("°C ");

  // Wait a few seconds between measurements.
  delay(2000);
}