| 52 | |
| 53 | |
| 54 | int8_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 | |
| 78 | int DHT12::_readSensor() |
no outgoing calls