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.

Double timer, with time on and off
#1
Hello, any example of a script for a timer with active operating time and resting time?

I have a 1 bit signal from a presence detector. When this signal is activated, I need to create a cycle of: activating a bomb for 5 minutes and then deactivating it for 15 minutes. If after this time cycle, the detector signal is still active or is activated again, repeat the cycle.
Reply
#2
Event script:
Code:
if event.getvalue() then
  storage.set('presence_time', os.time())  
end

Resident script with sleep time set to 1 second:
Code:
curr_trig_time = storage.get('presence_time', 0)

if not prev_trig_time then
  prev_trig_time = curr_trig_time
end

if curr_trig_time > prev_trig_time then
  prev_trig_time = curr_trig_time

  grp.write('0/0/2', true)
  os.sleep(5 * 60)
  grp.write('0/0/2', false)
  os.sleep(15 * 60)
end
Reply


Forum Jump: