Hello Guest it is March 28, 2024, 05:18:39 AM

Author Topic: 3 position toggle button  (Read 929 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  562 562
    • View Profile
3 position toggle button
« on: April 12, 2019, 03:04:36 PM »
Has anyone made a toggle button that has 3 states?
Ex; On, Off, Auto

I think i can do it with a regular button and use led indicators but it would be nice to just have the button change.

Thanks,
Bill
Re: 3 position toggle button
« Reply #1 on: April 13, 2019, 12:15:19 PM »
My initial approach would be to use a regular button and on the LeftUp script I would check the label:
If scr.getProperty("MyBtnName","Label")=="ON" then
  scr.setProperty("MyBtnName","Label","OFF")
  set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="OFF" then
  scr.setProperty("MyBtnName","Label","AUTO")
  set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="AUTO" then
   scr.setProperty("MyBtnName","Label","ON")
  set a register or send a signal and or change the background color or call a function
end

Haven't done any LUA programming lately so you would have to check the above syntax for errors.

HTH

RT

Offline MN300

*
  •  297 297
    • View Profile
Re: 3 position toggle button
« Reply #2 on: April 13, 2019, 12:57:31 PM »
rhtuttle's script should work but I would omit the last IF statement and rearrange it. If you reach that point you have checked the other two possibilities. If somehow "MyBtnName" is not one of the choices you would still set a valid value. I would make that default choice   "OFF".

If scr.getProperty("MyBtnName","Label")=="OFF" then
  scr.setProperty("MyBtnName","Label","AUTO")
  --set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="AUTO" then
  scr.setProperty("MyBtnName","Label","ON")
  --set a register or send a signal and or change the background color or call a function
else      scr.setProperty("MyBtnName","Label","OFF")
  --set a register or send a signal and or change the background color or call a function
end

Offline Bill_O

*
  •  562 562
    • View Profile
Re: 3 position toggle button
« Reply #3 on: April 15, 2019, 08:24:20 AM »
thanks all
i will give it a try

bill

Offline Bill_O

*
  •  562 562
    • View Profile
Re: 3 position toggle button
« Reply #4 on: April 15, 2019, 09:40:26 AM »
This worked great.

I made a register (iRegs0/MistSet)
Then I check the value of the register to change the button.

local inst = mc.mcGetInstance()
local hregmist = mc.mcRegGetHandle(inst, 'iRegs0/MistSet')
local MistNow = mc.mcRegGetValue(hregmist)
if (MistNow == 0) then
   scr.SetProperty('btnMistSet', 'Label', 'Mist Auto')
   mc.mcRegSetValue(hregmist, 1)
elseif (MistNow == 1) then
   scr.SetProperty('btnMistSet', 'Label', 'Mist On')
   mc.mcRegSetValue(hregmist, 2)
else
   scr.SetProperty('btnMistSet', 'Label', 'Mist Off')
   mc.mcRegSetValue(hregmist, 0)
end

Works like a champ and I can use the register values throughout Mach4.

Thanks for the help.
Bill