To create a simple M code that will turn an output on or off, you need to create a new LUA file. Within your Mach4Hobby folder, find the application called mcLuaEditor.exe and run that.
This is where you will begin coding.
Paste the following script in the editor and modify it as needed.
--This function will be used to turn on specific outputs.
function m101() --modify to create appropriate function. must follow "M-Code" format
local rc = 0; --return code.
local inst = mc.mcGetInstance(); --retrieve the current instance of MACH
--modify the following variables to match the output you wish to turn on/off.
local signal = mc.OSIG_OUTPUT0;
local message1 = "Output 0 ON";
-- Turns on/off the output.
hsig, rc = mc.mcSignalGetHandle(inst, signal);
mc.mcSignalSetState(hsig, 1); --use 0 to turn the output off and 1 to turn the output on
--Creates a message in the History
mc.mcCntlSetLastError(inst, message1);
end --This is for the end of the function
next, click File -> Save/SaveAs and navigate to Mach4Hobby/Profiles/My Profile/Macros
name the file the same as the function name (M-Code format). in this case M101
then use your newly created MCode within your G-Code or MDI!
Repeat for any additional outputs turning on or off.