#include <DHT.h>
#include <TM1637Display.h>
#define sensor 2
#define CLK 9
#define DIO 10
#define led 7
const unsigned int button = 7;
bool humidityOn = false;
#define DHTTYPE DHT22
DHT dht(sensor, DHTTYPE);
TM1637Display display = TM1637Display(CLK, DIO);
const uint8_t celsius[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Degree symbol
SEG_A | SEG_D | SEG_E | SEG_F // C
};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
display.clear();
display.setBrightness(7);
pinMode(button, INPUT_PULLUP);
pinMode(led, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int h = dht.readHumidity();
int t = dht.readTemperature();
if (humidityOn == false) {
display.showNumberDec(t, false, 2, 0);
display.setSegments(celsius, 2, 2);
if (t >= 40 || h >= 95) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
delay(2000);
display.clear();
humidityOn = true;
}
if (humidityOn == true) {
display.showNumberDec(h, false, 2, 0);
if (t >= 40 || h >= 95) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
delay(2000);
display.clear();
humidityOn = false;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println("'C");
}