41
Mach4 General Discussion / Re: How do you make a screen button turn on and off a relay?
« on: January 19, 2023, 08:51:14 AM »
In the signal library section of the screen script, you can use an INPUT for the button, then have it trigger your output.
Here's an example of a button triggering the coolant pump relay. You'll just have to figure out how to trigger YOUR OUTPUT.
----------Mach4 Input 17 PoKeys Pin 17-----
----------Toggle Coolant M8----------------
[mc.ISIG_INPUT17] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 0) then
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,1)
mc.mcCntlSetLastError(inst, "Coolant On")
else
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,0)
mc.mcCntlSetLastError(inst, "Coolant Off")
end
end
end,
Here's an example of a button triggering the coolant pump relay. You'll just have to figure out how to trigger YOUR OUTPUT.
----------Mach4 Input 17 PoKeys Pin 17-----
----------Toggle Coolant M8----------------
[mc.ISIG_INPUT17] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 0) then
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,1)
mc.mcCntlSetLastError(inst, "Coolant On")
else
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,0)
mc.mcCntlSetLastError(inst, "Coolant Off")
end
end
end,