Prepare variable environment for I2C communication

This commit is contained in:
bzi 2019-02-21 21:04:22 +01:00
parent 1df37cb910
commit 05ada31f0e

View File

@ -20,6 +20,10 @@ DHT dht(DHT_PIN, DHT_TYPE);
int sensorValue;
long last_sample = 0;
float hmid = 0; // humidity
float temp = 0; // temperature
float heat = 0; // heat index
float airq = 0; // air quality / gas
void setup() {
Serial.begin(SERIAL_BAUDRATE);
@ -38,25 +42,25 @@ void loop() {
last_sample = now;
if (OPERATION_BLINK_EN) {digitalWrite(LED_BUILTIN, HIGH);}
float h = dht.readHumidity();
float t = dht.readTemperature();
hmid = dht.readHumidity();
temp = dht.readTemperature();
if (isnan(h) || isnan(t)) {
if (isnan(hmid) || isnan(temp)) {
Serial.println(F("Failed to read from DHT sensor!"));
} else {
float hi = dht.computeHeatIndex(t, h, false);
heat = dht.computeHeatIndex(temp, hmid, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(hmid);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(temp);
Serial.print(F("°C Heat index: "));
Serial.print(hi);
Serial.println(F("°C "));
Serial.print(heat);
Serial.print(F("°C "));
}
sensorValue = analogRead(MQ135_PIN);
Serial.print("AirQuality=");
Serial.print(sensorValue, DEC);
airq = analogRead(MQ135_PIN);
Serial.print("AirQuality: ");
Serial.print(airq);
Serial.println(" PPM");
}
}