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

#define DHTPIN1 4
#define DHTTYPE DHT22 
DHT dht1(DHTPIN1, DHTTYPE); 

#define DHTPIN2 16    
DHT dht2(DHTPIN2, DHTTYPE);

LiquidCrystal lcd(12, 14, 27, 26, 25, 33);

int buttonPin = 5;     
int redPin = 32;      
int greenPin = 13;     
bool ledState = false; 
bool displayFirstSensor = true; 

void setup() {
    lcd.begin(16, 2);
    dht1.begin();
    dht2.begin();
    pinMode(buttonPin, INPUT_PULLUP);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
}

void loop() {

    if (digitalRead(buttonPin) == LOW) {
        displayFirstSensor = !displayFirstSensor; 
        delay(300); 
    }

    float humidity;
    float temperature;

    if (displayFirstSensor) {
        humidity = dht1.readHumidity();
        temperature = dht1.readTemperature();
        
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Temp1: ");
        lcd.print(temperature);
        lcd.print(" C");

        lcd.setCursor(2, 1);
        lcd.print("Hum1: ");
        lcd.print(humidity);
        lcd.print(" %");
        digitalWrite(redPin, HIGH);
        digitalWrite(greenPin, LOW);
    } else {
        humidity = dht2.readHumidity();
        temperature = dht2.readTemperature();
        
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Temp2: ");
        lcd.print(temperature);
        lcd.print(" C");

        lcd.setCursor(2, 1);
        lcd.print("Hum2: ");
        lcd.print(humidity);
        lcd.print(" %");
        digitalWrite(redPin, LOW);
        digitalWrite(greenPin, HIGH);
    }

    delay(1000);
}