Example: RGB control from LogicMachine

Task

How is it possible to control RGB LED strips from LogicMachine color palette? You have to create a script which will split 3byte object in 3 x 1byte objects which are then sent into KNX bus. Also there is another script to see the status ob the LEDs which is creating 3byte object from 3 x 1byte objects.

Add RGB object

In Objects menu add KNX object with Data type = RGB color:

rgb_objects_lm

Adjust Vis.parameters for this created object – choose necessary presets:

vis_parameters_RGB_LM

Once the object is added into visualization map, it looks like this:

rgb_color_palette_LM

Event-based program to split 3byte into 3x1byte

Source code    
  1. ------------------- Configurable parameters ----------------------------------------------------------
  2. redGroup = '1/1/5' --- modify ether group address or name of group
  3. greenGroup = 'LED1 Green Value' --- modify ether group address or name of group
  4. blueGroup = '1/1/7' --- modify ether group address or name of group
  5. ----------------------------------------------------------------------------------------------------------------
  6. value = event.getvalue()
  7. Blue= bit.band(value, 0xFF)
  8. Green = bit.rshift(bit.band(value, 0xFF00), 8)
  9. Red = bit.rshift(bit.band(value, 0xFF0000), 16)
  10. grp.write(redGroup, Red)
  11. grp.write(greenGroup, Green)
  12. grp.write(blueGroup, Blue)

Event-based program to combine 3x1byte into 3byte object to see status

Source code    
  1. ------------------- Configurable parameters ---------------------------
  2. redGroup = '1/1/1' --- either group address or name
  3. greenGroup = 'LED1 Green Status' --- either group address or name
  4. blueGroup = '1/1/3' --- either group address or name
  5. rgbGroup = 'RGB Value' --- either group address or name
  6. -----------------------------------------------------------------------
  7. red = grp.find(redGroup)
  8. green = grp.find(greenGroup)
  9. blue = grp.find(blueGroup)
  10.  
  11. rgb = bit.bor(bit.lshift(red, 16), bit.lshift(green, 8), blue)
  12. grp.update(rgbGroup, rgb)