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