Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Measure times ON-OFF Bit
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Dandrade
(5 posts) Bio
|
Date
| Wed 08 Nov 2006 08:43 PM (UTC) |
Message
|
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 08 Nov 2006 10:13 PM (UTC) |
Message
| I don't see what this has to do with MUSHclient, but I think you will find that the standard Lua functions won't return more resolution than 1 second, because that is all the underlying operating system calls do.
You may need to write your own function in C that returns higher resolution, and call that from Lua.
For things that are merely Lua questions, and not at all related to the other content of this site, I suggest using the Lua mailing list, they are quite helpful. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
8,867 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top