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.

convert percentage to 3 digital outputs
#4
Hi, is that what you need?

Code:
percent_val = event.getvalue() -- your value

--the first 5-30%, the second between 35-70% and the third between 75-100%.

first_obj = '5/0/1' -- address of first object
second_obj = '5/0/2' -- address of second object
third_obj = '5/0/3'  -- address of third object

if(percent_val >= 0 and percent_val < 5) then -- turn off
  grp.write(first_obj, 0) -- first object set to 0
  grp.write(second_obj, 0) -- second object set to 0
  grp.write(third_obj, 0) -- third object set to 0
elseif( percent_val >= 5 and percent_val <= 30 ) then
  grp.write(first_obj, 1) -- first object set to 1
  grp.write(second_obj, 0) -- second object set to 0
  grp.write(third_obj, 0) -- third object set to 0
elseif( percent_val >= 35 and percent_val <= 70 ) then
  grp.write(first_obj, 0)
  grp.write(second_obj, 1)
  grp.write(third_obj, 0)
elseif( percent_val >= 75 and percent_val <= 100 ) then
  grp.write(first_obj, 0)
  grp.write(second_obj, 0)
  grp.write(third_obj, 1)
end
Reply


Messages In This Thread
RE: convert percentage to 3 digital outputs - by RomansP - 14.06.2022, 10:03

Forum Jump: