【发布时间】:2017-05-20 09:38:20
【问题描述】:
我目前正在做一个项目,我需要读出DHT11 humidity and temperature sensor。 MCU 和串行设备之间的通信非常低级,但我设法将测量值(湿度+温度)接收为长度为 4 的字节数组(第 5 个字节是校验和):
我从 DHT11 传感器收到的值:
- byte[0] = humidity integer part
- byte[1] = humidity decimal part
- byte[2] = temperature integer part
- byte[3] = temperature decimal part
- byte[4] = checksum of the first four bytes
我现在想将byte[0] 和byte[1] 转换为浮点数,温度也一样(字节[2] 和字节[3])。在 C/C++ 中的 Arduino Mega 2560 上完成此任务的有效方法是什么?
例子:
byte[0] = 20 and byte[1] = 12 => 20.12 [float]
【问题讨论】: