This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Delay script
#9
(08.12.2022, 13:02)admin Wrote: Resident script with 0 sleep time. Single script can be used for multiple timers by adding more entries to the timers table at the top of the script.
Code:
if not client then   timers = {     ['1/1/1'] = {       output = '1/1/2', -- binary output       delayon = 10, -- on delay time (seconds)       delayoff = 0, -- off delay time (seconds)     }   }   grp.sender = 'tm'   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         timer.ticks = timer['delay' .. state]       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       grp.checkwrite(timer.output, timer.state == 'on')       timer.state = nil       timer.ticks = nil     end   end end
I use the script above when the input becomes 1 the output becomes 1 10 seconds later. If the input becomes 0 the output stays 1 not going back to 0. What is the problem?
Reply


Messages In This Thread
Delay script - by josdegroot - 08.12.2022, 10:41
RE: Delay script - by admin - 08.12.2022, 10:59
RE: Delay script - by josdegroot - 08.12.2022, 11:29
RE: Delay script - by admin - 08.12.2022, 13:02
RE: Delay script - by KoBra - 15.08.2023, 16:32
RE: Delay script - by josdegroot - 08.12.2022, 15:49
RE: Delay script - by josdegroot - 10.12.2022, 07:56
RE: Delay script - by admin - 10.12.2022, 11:27
RE: Delay script - by josdegroot - 11.12.2022, 07:42
RE: Delay script - by admin - 16.08.2023, 06:19
RE: Delay script - by KoBra - 17.08.2023, 13:43
RE: Delay script - by myg - 17.08.2023, 10:27
RE: Delay script - by admin - 17.08.2023, 10:31
RE: Delay script - by sjfp - 15.11.2023, 12:02
RE: Delay script - by admin - 15.11.2023, 14:26
RE: Delay script - by ErkinVural - 23.01.2024, 09:26
RE: Delay script - by sjfp - 15.11.2023, 14:35
RE: Delay script - by Daniel - 17.11.2023, 13:34
RE: Delay script - by sjfp - 17.11.2023, 13:48
RE: Delay script - by admin - 22.11.2023, 09:52
RE: Delay script - by sjfp - 22.11.2023, 11:27

Forum Jump: