Example: DMX lighting control with LM2

DMX function

There is a DMX function already added by default in Logic Machine -> Scripts -> Tools menu.

Usage

  1. d = DMX:init(parameters)
  2. 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:

  1. if not d then
  2. d = DMX:init({
  3. channels = 3,
  4. transition = 2,
  5. })
  6. end
  7.  
  8. d:run()

 
Setter (used in other scripts):

  1. 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).

  1. if not scenes then
  2. -- 3 channel scene
  3. scenes = {
  4. { 255, 0, 0 },
  5. { 0, 255, 0 },
  6. { 0, 0, 255 },
  7. { 255, 255, 0 },
  8. { 0, 255, 255 },
  9. { 255, 0, 255 },
  10. { 255, 255, 255 },
  11. }
  12.  
  13. current = 1
  14. end
  15.  
  16. -- set current scene values
  17. scene = scenes[ current ]
  18. for i, v in ipairs(scene) do
  19. DMX.set(i, v)
  20. end
  21.  
  22. -- switch to next scene
  23. current = current + 1
  24. if current > #scenes then
  25. current = 1
  26. end

 

Random scene example:
The following example should be placed inside a resident script. Sleep time defines scene keep time (at least 1 second).

  1. -- number of steps to use, e.g. 3 steps = { 0, 127, 255 }
  2. steps = 5
  3. -- number of channels to set
  4. channels = 3
  5. -- first channel number
  6. offset = 1
  7.  
  8. for i = offset, channels do
  9. v = math.random(0, (steps - 1)) * 255 / (steps - 1)
  10. DMX.set(i, math.floor(v))
  11. end