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

Method read

libraries/DHT12/DHT12.cpp:54–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53
54int8_t DHT12::read()
55{
56 // READ SENSOR
57 int status = _readSensor();
58 if (status < 0) return status;
59
60 // CONVERT AND STORE
61 _humidity = _bits[0] + _bits[1] * 0.1;
62 _temperature = _bits[2] + (_bits[3] & 0x7F) * 0.1;
63 if (_bits[3] & 0x80)
64 {
65 _temperature = -_temperature;
66 }
67
68 // TEST CHECKSUM
69 uint8_t checksum = _bits[0] + _bits[1] + _bits[2] + _bits[3];
70 if (_bits[4] != checksum) return DHT12_ERROR_CHECKSUM;
71
72 _lastRead = millis();
73
74 return DHT12_OK;
75}
76
77
78int DHT12::_readSensor()

Callers 2

_readSensorMethod · 0.45
unittestFunction · 0.45

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.36