23.01.2024, 09:26
(This post was last modified: 23.01.2024, 11:14 by ErkinVural.)
(15.11.2023, 14:26)admin Wrote: Create user library named timers:
Code:return function(timers) if not client then grp.sender = 'tm' function set(timer) grp.checkwrite(timer.output, timer.state == 'on') timer.state = nil timer.ticks = nil end client = require('localbus').new(0.1) client:sethandler('groupwrite', function(event) local timer = timers[ event.dst ] if timer and event.sender ~= grp.sender then local value = tonumber(event.datahex, 16) or 0 local state = value > 0 and 'on' or 'off' if timer.state ~= state then timer.state = state local ticks = timer['delay' .. state] if ticks > 0 then timer.ticks = ticks else set(timer) end end end end) end client:loop(1) for _, timer in pairs(timers) do if timer.ticks then timer.ticks = timer.ticks - 1 if timer.ticks == 0 then set(timer) end end end end
Resident script:
Code:if not timers then timers = { ['1/1/1'] = { output = '1/1/2', -- binary output delayon = 10, -- on delay time (seconds) delayoff = 0, -- off delay time (seconds) } } end require('user.timers')(timers)
Hello, I will need a different version of the code above. When x1, x2, x3, ... all evaluate to true, it should again produce a single output 10 seconds later.
I would be very grateful if you could help, thank you.
Edit: Hello, I think I've found the solution. I'm sharing it below.
Code:
if not timers then
timers = {
['7/0/1' and '7/0/3' and '7/0/5'] = {
output = '7/0/7', -- binary output
delayon = 0, -- on delay time (seconds)
delayoff = 0, -- off delay time (seconds)
}
}
end
require('user.timers')(timers)