Hello Guest it is March 28, 2024, 04:42:20 PM

Author Topic: Button with two functions  (Read 6954 times)

0 Members and 1 Guest are viewing this topic.

Button with two functions
« on: August 25, 2011, 04:28:13 PM »
Hello all,
on my pendant I have momentary switch connected to OEMTRIGGER5. How can I make this switch to activate output5 (output must stay active) and then with the same button deactivate output5? I've been trying this all day with no luck. Can somebody please help?

Peter

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Button with two functions
« Reply #1 on: August 25, 2011, 08:21:02 PM »
SOmething along these lines may work,  I have seen a better example on here somewhere.


Sub Main()
If OemTrigger1 And GetVar(1000)< 1 Then GoTo N2
If OemTrigger1 And GetVar(1000)> 0 Then GoTo N3
GoTo N4

N2:
ActivateSignal(output5)
SetVar(1000,1)
GoTo N4

N3:
DeactivateSignal(output5)
SetVar(1000,0)
GoTo N4

N4:
End Sub
End


OR maybe something like this

If OemTrigger1 And GetVar(1000)<1 Then                
   ActivateSignal(output5)
   SetVar(1000,1)                              '
  End If                                        

  If OemTrigger1 And GetVar(1000)>0 Then                '
   ActivateSignal(output5)
   SetVar(1000,0)                              
  End If        
  
  End

Hope it helps, (;-) TP

« Last Edit: August 25, 2011, 08:33:15 PM by BR549 »
Re: Button with two functions
« Reply #2 on: August 26, 2011, 03:48:05 PM »
Hi BR549,
thanks for reply. I've tried your second code you posted. I put it in the macropump and it didn't worked. Then I've tried with IsActive(OEMTRIG1) instead OemTrigger1 and it worked. The output 5 becomes active. The only problem is that I can't turn it off with the same button. What do I need to change in the code?

If IsActive(OEMTRIG1) And GetVar(1000)<1 Then               
   ActivateSignal(output5)
   SetVar(1000,1)                              '
  End If                                       

  IsActive(OEMTRIG1) And GetVar(1000)>0 Then                '
   ActivateSignal(output5)
   SetVar(1000,0)                             
  End If       
 
  End

Peter

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Button with two functions
« Reply #3 on: August 26, 2011, 03:59:35 PM »
Look at the second part of your example it is using ActivateSignal(output5)  It needs to be DeactivateSignal(output5).

If that does not do it then try using a lower var number such as 600.

(;-) TP

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Button with two functions
« Reply #4 on: August 27, 2011, 04:27:21 AM »
Or...

Code: [Select]
If isActive(OEMTRIG5) then
  if isOutputActive(OUTPUT5) then
     deActivateSignal(OUTPUT5)
  else
     ActivateSignal(OUTPUT5)                   '
end if

however, using the macropump to respond to triggers is kinda missing the point of triggers...  ;)

Ian
« Last Edit: August 27, 2011, 04:29:38 AM by stirling »
Re: Button with two functions
« Reply #5 on: August 27, 2011, 07:14:14 AM »
Hi stirling,
I've tried your code but I get syntax error. Must be something wrong in the code.
Re: Button with two functions
« Reply #6 on: August 27, 2011, 07:36:38 AM »
Ok I put another End If at the end of the code

If IsActive(OEMTRIG5) Then
If IsOutputActive(OUTPUT5) Then
DeActivateSignal(OUTPUT5)
Else
ActivateSignal(OUTPUT5)
End If                 
End If

Now the problem is that when I press the button the output does not come on. The LED of the output comes on and then turns off. If I hold button for longer time, output LED blinks tree or more times and then stay active. If I deactivate output I also must hold button for longer time, then LED blinks tree times and then turns off.

Peter
Re: Button with two functions
« Reply #7 on: August 27, 2011, 07:46:54 AM »
I've find this topic of self made pendant

http://www.machsupport.com/forum/index.php/topic,2823.0.html

this guy is using stop button with two funtions. Hold button less than one second pause the program, hold button more than one second stops the program. I was looking at his macropump file and I can't figure out how he made it.

Peter

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Button with two functions
« Reply #8 on: August 27, 2011, 09:05:13 AM »
Peter - yes - I mislaid an "end if" but you found it - fingers not keeping up with head again.

The problem you're encountering is ONE reason why I said earlier that this is not the best way to do it. The macropump is running at 10Hz so it's not unreasonable that when you press the button the macropump reads it several times - what you end up with is a rather nice game of roulette. The macropump POLLS the state of the input. A TRIGGER acts like an interrupt and executes it's macro on the active state change of the input. This does away with this problem.

see http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160

Ian
« Last Edit: August 27, 2011, 09:51:37 AM by stirling »
Re: Button with two functions
« Reply #9 on: August 27, 2011, 03:00:05 PM »
Peter - yes - I mislaid an "end if" but you found it - fingers not keeping up with head again.

The problem you're encountering is ONE reason why I said earlier that this is not the best way to do it. The macropump is running at 10Hz so it's not unreasonable that when you press the button the macropump reads it several times - what you end up with is a rather nice game of roulette. The macropump POLLS the state of the input. A TRIGGER acts like an interrupt and executes it's macro on the active state change of the input. This does away with this problem.

see http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160

Ian

Thanks Ian now it's working.

Peter
« Last Edit: August 27, 2011, 03:07:07 PM by peter81 »