GY-63_MS5611/libraries/SHT31/examples/SHT31_heater/SHT31_heater.ino

70 lines
1.1 KiB
Arduino
Raw Normal View History

2020-11-27 05:33:55 -05:00
//
// FILE: SHT31_heater.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo heater functions
// URL: https://github.com/RobTillaart/SHT31
2021-05-28 07:45:10 -04:00
2020-11-27 05:33:55 -05:00
#include "Wire.h"
#include "SHT31.h"
2021-01-29 06:31:58 -05:00
#define SHT31_ADDRESS 0x44
2020-11-27 05:33:55 -05:00
SHT31 sht;
2021-01-29 06:31:58 -05:00
uint16_t status;
2020-11-27 05:33:55 -05:00
2021-05-28 07:45:10 -04:00
2020-11-27 05:33:55 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("SHT31_LIB_VERSION: \t");
Serial.println(SHT31_LIB_VERSION);
Wire.begin();
2021-01-29 06:31:58 -05:00
sht.begin(SHT31_ADDRESS);
2020-11-27 05:33:55 -05:00
Wire.setClock(100000);
sht.setHeatTimeout(30); // heater timeout 30 seconds, just for demo.
2021-01-29 06:31:58 -05:00
status = sht.readStatus();
printHeaterStatus(status);
2020-11-27 05:33:55 -05:00
sht.heatOn();
2021-01-29 06:31:58 -05:00
while (sht.isHeaterOn())
2020-11-27 05:33:55 -05:00
{
2021-01-29 06:31:58 -05:00
status = sht.readStatus();
printHeaterStatus(status);
2020-11-27 05:33:55 -05:00
sht.read();
Serial.println(sht.getTemperature());
delay(10000);
}
Serial.println("switched off");
}
2021-05-28 07:45:10 -04:00
2020-11-27 05:33:55 -05:00
void loop()
{
// forced switch off
2021-01-29 06:31:58 -05:00
if (status & SHT31_STATUS_HEATER_ON) sht.heatOff();
2020-11-27 05:33:55 -05:00
}
2021-01-29 06:31:58 -05:00
void printHeaterStatus(uint16_t status)
2020-11-27 05:33:55 -05:00
{
Serial.print(millis());
Serial.print("\tHEATER: ");
2021-01-29 06:31:58 -05:00
if (status & SHT31_STATUS_HEATER_ON)
2020-11-27 05:33:55 -05:00
{
Serial.println("ON");
} else {
Serial.println("OFF");
}
}
2021-05-28 07:45:10 -04:00
2020-11-27 05:33:55 -05:00
// -- END OF FILE --
2021-12-28 06:31:55 -05:00