Shutter controller based on LogicMachine #
Common function #
Place shutters
function parameters in Scripting > Common functions.
function shutters(event, in_a, in_b, out_a, out_b, mode_alt)
local value = event.getvalue()
local out, out_alt
-- a = move up/down; b = stop
if mode_alt then
-- true (up) = output a, false (down) = output b
out = value and out_a or out_b
-- output value for input a (up/down) = true, for input b (stop) = false
value = event.dst == in_a
-- a = move up/stop; b = move down/stop
else
-- event from input a = output a, event for input b = output b
out = event.dst == in_a and out_a or out_b
end
-- alternative output, a => b / b => a
out_alt = out == out_a and out_b or out_a
-- turn off alternative output
grp.checkwrite(out_alt, false)
grp.checkwrite(out, value)
end
Event script #
Create event scripts for two input objects (same script for each input).
Standard mode: input A = move up/stop; input B = move down/stop:
shutters(event, '1/1/1', '1/1/2', '1/1/3', '1/1/4')
Alternative mode: input A = move up/down; input B = stop:
shutters(event, '1/1/1', '1/1/2', '1/1/3', '1/1/4', true)
Addresses:
-
1/1/1
- input A -
1/1/2
- input B -
1/1/3
- output (relay) A -
1/1/4
- output (relay) B
Automatically turn off relays (optional) #
To turn relays off automatically after a certain time add an auto-off
tag to each relay object.
Create a single resident script with 2-3 seconds of sleep time. Adjust maxdelta
variable as needed.
maxdelta = 60 -- turn off after 60 seconds
objs = grp.tag('auto-off')
for _, obj in ipairs(objs) do
if obj.value then
delta = os.time() - obj.updatetime
if delta >= maxdelta then
obj:write(false)
end
end
end