Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DewPoint_Sensor_NormalScreen disp70 disp70 DPTimer_NormalScreen_8R_DIP_4-20mA_Out
HYT.cpp
00001 #include "HYT.h" 00002 #include "mbed.h" 00003 00004 HYT::HYT(PinName sda, PinName scl) : _i2c(sda, scl) 00005 { 00006 } 00007 00008 /*************************************************************************************************************************/ 00009 void HYT::MRCommand(void) 00010 { 00011 _i2c.write(HYT_ADDR, 0, 0); 00012 } 00013 00014 00015 /*************************************************************************************************************************/ 00016 int HYT::DFCommand(void) 00017 { 00018 char dataI2C[4]; 00019 int stateBit; 00020 int humidityRaw; 00021 int temperatureRaw; 00022 00023 _i2c.read(HYT_ADDR, dataI2C, 4); 00024 00025 stateBit = (dataI2C[0] & 0x40) >> 6; 00026 if (stateBit == 0) { 00027 humidityRaw = ((dataI2C[0] & 0x3F) << 8) | dataI2C[1]; 00028 temperatureRaw = ((dataI2C[2] << 8) | dataI2C[3]) >> 2; 00029 if (temperatureRaw < 0x3FFF && humidityRaw < 0x3FFF) { 00030 temperature = ((float)(temperatureRaw) * 165.0f / 16383.0f) - 40.0f; 00031 humidity = (float)humidityRaw * 100.0f / 16383.0f; 00032 } else { 00033 // sensor returns wrong data (1111...11) 00034 return -1; 00035 } 00036 } else { 00037 // no new value received from sensor 00038 return -2; 00039 } 00040 00041 return 0; 00042 }
Generated on Thu Jul 21 2022 01:26:51 by
1.7.2