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

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  // Пины RS, Enable, D4-D7
Servo myservo;

int potPin = A0;
int ledPin = 13;
int thresholdTemp = 5;
int blinkInterval = 200;

void setup() {
  Serial.begin(9600);
  dht.begin();
  lcd.begin(16, 2);
  lcd.print("Temp: ");
  lcd.setCursor(0, 1);
  lcd.print("prosVolt: ");
  myservo.attach(10); // Пин 10 для сервопривода
  pinMode(ledPin, OUTPUT);
}

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

  int potValue = analogRead(potPin);
  int mappedValue = map(potValue, 0, 1023, 0, 100);

  lcd.setCursor(6, 0);
  lcd.print(temperature);
  lcd.print(" C");

  lcd.setCursor(10, 1);
  lcd.print(mappedValue);

  if (temperature < thresholdTemp) {
    digitalWrite(ledPin, HIGH);
    delay(5);
    digitalWrite(ledPin, LOW);
    delay(5);
  } else {
    digitalWrite(ledPin, LOW);
  }

  int servoPosition = (mappedValue > 50) ? 180 : 0;
  myservo.write(servoPosition);

  delay(2000);
}