Make to builder one function for measure times duration, period for each signal identific positive and negative.
Objetive function "create" variables for each signal and return values about times and signal positive/negative.
My function,memory before/after time to read bit, and return the values times.Have error about nil function and the variables, dont know automatic create variables.
Have this moment it function:
t=os.date('*t') --get hardware clock time
function duty_cly(sensor)
local pol="negativo"
local duracao
--input.sinal[sensor]= get_bit(sensor) after is add
if(input.sinal[sensor] == true)then
pol="positivo"
if(input.t2b[sensor] == true) then
input.t2a[sensor]=t
input.t2b[sensor]=t
input.t1b[sensor]=nil
else
input.t2a[sensor]=t
end
duracao=os.difftime (input.t2b[sensor], input.t2a[sensor])
else -- se sinal for negativo
if(input.t1b[sensor] == true) then
input.t1a[sensor]=t
input.t1b[sensor]=t
input.t2b[sensor]=nil
else
input.t1a[sensor]=t
end
duracao=os.difftime (input.t1b[sensor], input.t1a[sensor])
end
contador(sensor) --call counter pulses
if not(input.t1a[sensor] == input.t2a[sensor]) then --processa somente quando existe tempo > 0seg
--Ignore if time equal segund
if(pol == "positivo")then
return pol ,os.difftime (input.t1b[sensor], input.t2a[sensor],duracao)
else
return pol ,os.difftime (input.t2b[sensor], input.t1a[sensor],duracao)
end
end
end
PS: Like to measure milisegund or 0.1 segundes, the instrutions os.date get only secundes.