/***************************************************
  This is an example for the SHT4x Humidity & Temp Sensor

  Designed specifically to work with the SHT4x sensor from Adafruit
  ----> https://www.adafruit.com/products/4885

  These sensors use I2C to communicate, 2 pins are required to  
  interface
 ****************************************************/

#include "Adafruit_SHT4x.h"

Adafruit_SHT4x sht4 = Adafruit_SHT4x();

void setup()
  { Serial.begin(115200);

    while (!Serial)
      delay(10);     // will pause Zero, Leonardo, etc until serial console opens

    Serial.println("Adafruit SHT4x test");
    if (! sht4.begin())
      { Serial.println("Couldn't find SHT4x");
        while (1) delay(1);
      }
    // Serial.print(" SHT4x sensor");
    // Serial.print("Serial number 0x");
    // Serial.println(sht4.readSerial(), HEX);

    Serial.printf(" SHT4x sensor S/N 0x%x\n", sht4.readSerial());

    // You can have 3 different precisions, higher precision takes longer
    sht4.setPrecision(SHT4X_HIGH_PRECISION);
    switch (sht4.getPrecision())
      { case SHT4X_HIGH_PRECISION: Serial.println("High precision"); break;
        case SHT4X_MED_PRECISION:  Serial.println("Med precision" ); break;
        case SHT4X_LOW_PRECISION:  Serial.println("Low precision" ); break;
      }  // switch precision

    // You can have 6 different heater settings
    // higher heat and longer times uses more power
    // and reads will take longer too!
    sht4.setHeater(SHT4X_NO_HEATER);
    switch (sht4.getHeater())
      { case SHT4X_NO_HEATER:         Serial.println("No heater"  ); break;
        case SHT4X_HIGH_HEATER_1S:    Serial.println("200 mW 1.0s"); break;
        case SHT4X_HIGH_HEATER_100MS: Serial.println("200 mW 0.1s"); break;
        case SHT4X_MED_HEATER_1S:     Serial.println("110 mW 1.0s"); break;
        case SHT4X_MED_HEATER_100MS:  Serial.println("110 mW 0.1s"); break;
        case SHT4X_LOW_HEATER_1S:     Serial.println(" 20 mW 1.0s"); break;
        case SHT4X_LOW_HEATER_100MS:  Serial.println(" 20 mW 0.1s"); break;
      } // switch heater
  } // setup


void loop()
  { sensors_event_t humidity, temp;

    uint32_t timestamp = millis();
    sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
    timestamp = millis() - timestamp;

    Serial.printf("Temperature: %.1f C RH %.0f%% in %d ms\n",
                     temp.temperature, humidity.relative_humidity, timestamp);
    delay(1000);
  } // loop