Logic Machine Forum
4-bit to 1-byte conversion script for DALI, DMX512 etc. - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: 4-bit to 1-byte conversion script for DALI, DMX512 etc. (/showthread.php?tid=13)



4-bit to 1-byte conversion script for DALI, DMX512 etc. - edgars - 02.07.2015

Resident script (sleep interval = 0), which is doing conversion from 4-bit to 1-byte

4-bit dimmer object adress is 1/1/1
1-byte output object adress is 1/1/2

By default, script will change value by 10% every 0.2 seconds when any kind of up/down telegram is received.
 
Code:
dimmer = grp.getvalue('1/1/1')
step = bit.band(dimmer, 0x07)

if step ~= 0 then
 addr = '1/1/2'
  up = bit.band(dimmer, 0x08) ~= 0
  value = grp.getvalue(addr)

  if up then
    newvalue = value + 10
  else
    newvalue = value - 10
  end

  -- clamp between 0 and 100
  newvalue = math.min(newvalue, 100)
  newvalue = math.max(newvalue, 0)

  if newvalue ~= value then
    grp.write(addr, newvalue)
  end
end

os.sleep(0.2)



RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - DarthPaul - 16.09.2016

(02.07.2015, 08:32)edgars Wrote: Resident script (sleep interval = 0), which is doing conversion from 4-bit to 1-byte

4-bit dimmer object adress is 1/1/1
1-byte output object adress is 1/1/2

By default, script will change value by 10% every 0.2 seconds when any kind of up/down telegram is received.
 
Code:
.....

I just cant make this work. I get an message: Lua syntax error at line 6: '=' expected near 'up'   It might just be too late at night...

edit:
Sorry.. just found the error... When copying your code RAW, and replacing it with my group addresses, something happened with the spaces.. When I deleted all space before code.. It worked.. adding space, still works?.. anyway, some copy-problems, works superb now.. thanks

Dont underestimate the Power of KNX
Darth Paul


RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - david.rombaut@gmail.com - 06.10.2018

Hello, I've been using this script succesfully for about 2 years to be able to control the volume of my Sonos system directly from KNX Berker pushbuttons.
I now tried to do the same thing to make simulatious dimming of multiple lights from 1 button possible but for some reason I am getting an error message: "bad argument, number expected, got boolean)
I've checked in ETS and address '2/1/17' is defined as 4 bit.

Anybody an idea on what I might be doing wrong here?

Thanks, David


RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - admin - 06.10.2018

Check that 2/1/17 has 4-bit type in LM Objects tab, ETS settings does not matter


RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - david.rombaut@gmail.com - 06.10.2018

(06.10.2018, 12:42)admin Wrote: Check that 2/1/17 has 4-bit type in LM Objects tab, ETS settings does not matter

Yep, that did the trick. Thanks a lot. Forgot that I have to define the objects in both ETS and LM  Blush


RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - Daniel - 03.06.2021

Change the +10, -10 in the code as you need


RE: 4-bit to 1-byte conversion script for DALI, DMX512 etc. - victor.back - 03.06.2021

(03.06.2021, 08:29)Daniel. Wrote: Change the +10, -10 in the code as you need

Thanks.

I think that I missed the os.sleep was at 5sec, so changed it to 1sec. 
Havent been able to try it out, but think that this was my issue Smile


EDIT:
I found that my issu was that I had set up an event based script, so this was just executed once, now I changed it to a resident script insted.