Commit 85727485 authored by robcazzaro's avatar robcazzaro
Browse files

Update dht22.lua

Addresses issue #225, slower loop timing due to the use of floats. Should be safe to use with integer-only builds, since on integer-only builds I could never see "3" as a valid value for either low or high
parent 7e524f7d
...@@ -62,17 +62,17 @@ function M.read(pin) ...@@ -62,17 +62,17 @@ function M.read(pin)
--DHT data acquired, process. --DHT data acquired, process.
for i = 1, 16, 1 do for i = 1, 16, 1 do
if (bitStream[i] > 4) then if (bitStream[i] > 3) then
humidity = humidity + 2 ^ (16 - i) humidity = humidity + 2 ^ (16 - i)
end end
end end
for i = 1, 16, 1 do for i = 1, 16, 1 do
if (bitStream[i + 16] > 4) then if (bitStream[i + 16] > 3) then
temperature = temperature + 2 ^ (16 - i) temperature = temperature + 2 ^ (16 - i)
end end
end end
for i = 1, 8, 1 do for i = 1, 8, 1 do
if (bitStream[i + 32] > 4) then if (bitStream[i + 32] > 3) then
checksum = checksum + 2 ^ (8 - i) checksum = checksum + 2 ^ (8 - i)
end end
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment