MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / read

Method read

libraries/CHT8305/CHT8305.cpp:73–94  ·  view source on GitHub ↗

/////////////////////////////////////////// READ THE SENSOR

Source from the content-addressed store, hash-verified

71// READ THE SENSOR
72//
73int CHT8305::read()
74{
75 // do not read too fast
76 if (millis() - _lastRead < 1000)
77 {
78 return CHT8305_ERROR_LASTREAD;
79 }
80 _lastRead = millis();
81
82 uint8_t data[4] = {0, 0, 0, 0 };
83 _readRegister(CHT8305_REG_TEMPERATURE, &data[0], 4);
84
85 uint16_t tmp = data[0] << 8 | data[1];
86 _temperature = tmp * (165.0 / 65535.0) - 40.0;
87 tmp = data[2] << 8 | data[3];
88 _humidity = tmp / 655.35; // == / 65535 * 100%
89
90 if (_tempOffset != 0.0) _temperature += _tempOffset;
91 if (_humOffset != 0.0) _humidity += _humOffset;
92
93 return CHT8305_OK;
94}
95
96
97int CHT8305::readTemperature()

Callers 2

_readRegisterMethod · 0.45
_requestMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected