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
#6
Erwin van der Zwart, thank you for your feedback.

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(second_obj, 0) -- second object set to 0
  grp.write(third_obj, 0) -- third object set to 0
  os.sleep(1) -- delay to do not have two objects on simultaneously
  grp.write(first_obj, 1) -- first object set to 1
elseif( percent_val >= 35 and percent_val <= 70 ) then
  grp.write(first_obj, 0)
  grp.write(third_obj, 0)
  os.sleep(1)
  grp.write(second_obj, 1)
elseif( percent_val >= 75 and percent_val <= 100 ) then
  grp.write(first_obj, 0)
  grp.write(second_obj, 0)
  os.sleep(1)
  grp.write(third_obj, 1)
end
Reply


Messages In This Thread
RE: convert percentage to 3 digital outputs - by RomansP - 15.06.2022, 06:30

Forum Jump: