This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

dim up / down to percentage
#1
I run this script to change up/down dim to a percentage but when it runs the logic machine goes in overload (100%) Is there another/better way?

Code:
dimmer = grp.getvalue('1/3/10')
step = bit.band(dimmer, 0x07)

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

  if up then
    newvalue = value + 5
  else
    newvalue = value - 5
  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)
Reply


Messages In This Thread
dim up / down to percentage - by KoBra - 15.10.2023, 18:45
RE: dim up / down to percentage - by KoBra - 15.10.2023, 20:16
RE: dim up / down to percentage - by admin - 16.10.2023, 05:52
RE: dim up / down to percentage - by KoBra - 16.10.2023, 09:31
RE: dim up / down to percentage - by admin - 16.10.2023, 09:36

Forum Jump: