Example: DMX lighting control with LM2
DMX function
There is a DMX function already added by default in Logic Machine -> Scripts -> Tools menu.

Usage
- d = DMX:init(parameters)
- d:run()
Parameters (table)
- channels – (optional, defaults to 3) number of DMX channels to use
- resolution – (optional, defaults to 20) number of DMX updates per second. Larger value gives smoother transitions, but increases CPU usage
- transition – (optional, defaults to 2) soft transition time in seconds
- port – (optional) RS-485 port name, usually you don’t have to change this value
Resident programms
DMX handler should be placed inside a resident script. Sleep time interval must be set to 0.

Once the script is added we can add the program source in script Editor:
- if not d then
- d = DMX:init({
- channels = 3,
- transition = 2,
- })
- end
-
- d:run()
Setter (used in other scripts):
- DMX.set(channel, value)
- channel – DMX channel number [1..512]
- value – DMX channel value [0..255]
Predefined scene example:
The following example should be placed inside a resident script. Sleep time defines scene keep time (at least 1 second).
- if not scenes then
- -- 3 channel scene
- scenes = {
- { 255, 0, 0 },
- { 0, 255, 0 },
- { 0, 0, 255 },
- { 255, 255, 0 },
- { 0, 255, 255 },
- { 255, 0, 255 },
- { 255, 255, 255 },
- }
-
- current = 1
- end
-
- -- set current scene values
- scene = scenes[ current ]
- for i, v in ipairs(scene) do
- DMX.set(i, v)
- end
-
- -- switch to next scene
- current = current + 1
- if current > #scenes then
- current = 1
- end
Random scene example:
The following example should be placed inside a resident script. Sleep time defines scene keep time (at least 1 second).
- -- number of steps to use, e.g. 3 steps = { 0, 127, 255 }
- steps = 5
- -- number of channels to set
- channels = 3
- -- first channel number
- offset = 1
-
- for i = offset, channels do
- v = math.random(0, (steps - 1)) * 255 / (steps - 1)
- DMX.set(i, math.floor(v))
- end




