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

#define DHT22_PIN 2
#define LED_PIN 5
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
dht DHT;
Servo myservo;  // create servo object to control a servo
int ppros = 48;
int aangl = 86;
int ttemp = 12;
int potpin = 2;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

struct {
  uint32_t total;
  uint32_t ok;
  uint32_t crc_error;
  uint32_t time_out;
  uint32_t connect;
  uint32_t ack_l;
  uint32_t ack_h;
  uint32_t unknown;
} stat = { 0, 0, 0, 0, 0, 0, 0, 0};

void clearScreen() {
  // Loop through each character on the screen
  for (int i = 0; i < 16; i++) {
    // Set the cursor to the current character
    lcd.setCursor(i, 0);
    // Write a space to the current character
    lcd.write(' ');
  }
}

void setup() {
  lcd.begin(16, 2);

  myservo.attach(6);
  pinMode(LED_PIN, OUTPUT);
  myservo.write(0);
  Serial.begin(115200); 
}

void loop() {
  if (analogRead(potpin) > ppros){
    myservo.write(aangl);
  }

  if (DHT.temperature < ttemp){
    digitalWrite(LED_PIN, HIGH);
    delay(100);
    digitalWrite(LED_PIN, LOW);
  }

  lcd.println(val);
  delay(200);
  lcd.println(DHT.temperature, 1);
  val = analogRead(potpin);
  int chk = DHT.read22(DHT22_PIN);


  Serial.print("prosVolt:");
  Serial.print(val);
  Serial.print("\tТемпература:");
  Serial.print(DHT.temperature, 1);
  Serial.print("\t Вологість:");
  Serial.print(DHT.humidity, 1);
  Serial.print("\t");

  Serial.println();

}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
pot1:GND
pot1:SIG
pot1:VCC
servo1:GND
servo1:V+
servo1:PWM
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
r1:1
r1:2
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
led1:A
led1:C
r2:1
r2:2