//#include <iostream>
#include "DHT.h"
class Sensor {
public:
virtual void begin() = 0;
virtual float readValue() = 0;
};
class AnalogSensor : public Sensor {
int pin;
public:
AnalogSensor(int pin) : pin(pin) {}
void begin() {
}
float readValue() {
//std::cout << "Analog Sensor Value: " << readValue() << std::endl;
return 0;
}
};
class DigitalSensor : public Sensor {
int pin;
DHT dht;
public:
DigitalSensor(int pin) : pin(pin), dht(pin, DHT22) {}
void begin() {
dht.begin();
}
float readValue() {
//std::cout << "Analog Sensor Value: " << readValue() << std::endl;
return 0;}
float readhumidity() {
dht.read();
float humidity = dht.readHumidity();
//std::cout << "DHT22 Humidity: " << humidity << "%" << std::endl;
return 0;
}
float readTemperatureCelsius() {
dht.read();
float temperatureC = dht.readTemperature();
//std::cout << "DHT22 Temperature (Celsius): " << temperatureC << "°C" << std::endl;
return 0;
}
};
void setup(){
AnalogSensor analogSensor(0);
DigitalSensor dht22(15);
pinMode(13, OUTPUT);
analogSensor.begin();
dht22.begin();
}
void loop(){
AnalogSensor analogSensor(0);
DigitalSensor dht22(15);
analogSensor.readValue();
dht22.readhumidity();
if(dht22.readhumidity()>50)
digitalWrite(13,HIGH);
delay(2000);
}