我正在使用类似于霍尔效应传感器的传感器来计数中断次数。经过一段随机时间后,通常在开启1-2小时后,它会重置并随后随机重置随机间隔。是什么导致我的Nodemcu/ESP 8266重置?
counter = 0;
sampletime = 0;
lastrisetime = tmr.now()
pin = 2
do
gpio.mode(pin, gpio.INT)
local function rising(level)
-- to eliminate multiple counts during a short period (.5 second) difference is taken
if ((tmr.now() - lastrisetime) > 500000) then
lastrisetime = tmr.now();
end
-- when tmr.now() resets to zero this takes into account that particular count
if ((tmr.now() - lastrisetime) < 0) then
lastrisetime = tmr.now();
end
end
local function falling(level)
if ((tmr.now() - lastrisetime) > 500000) then
-- Only counted when the pin is on falling
-- It is like a sine curve so either the peak or trough is counted
counter = counter + 1;
print(counter)
lastrisetime = tmr.now();
sampletime = lastrisetime;
end
-- when tmr.now() resets to zero this takes into account that particular count
if ((tmr.now() - lastrisetime) < 0) then
lastrisetime = tmr.now();
counter = counter + 1;
print(counter)
end
end
gpio.trig(pin, "up", rising)
gpio.trig(pin, "down", falling)
end
这是我得到CoolTerm错误,我也检查了内存每隔几个小时,你可以在那里看到的结果。
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> Connecting...
connected
print(node.heap())
22920
> print(node.heap())
22904
> print(node.heap())
22944
> print(node.heap())
22944
> 2. .print(node.heap())
22944
> print(node.heap())
22944
> ∆.)ç˛.䂸 ã ¸@H7.àåË‘
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> Connecting...
connected
print(node.heap())
21216
> F.)ç˛.¶Ùå¶[email protected] .ÊÍ
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> Connecting...
connected
H!໩.ä‚D.ã ¸å¶H.åb‘
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
> Connecting...
connected
print(node.heap())
22904
> print(node.heap())
21216
>
感谢您花时间阅读本文。感谢您的意见。
问题解决了吗?如果是这样,请考虑[upvoting/accepting](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)答案。 –