Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: peter81 on August 25, 2011, 04:28:13 PM

Title: Button with two functions
Post by: peter81 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
Title: Re: Button with two functions
Post by: BR549 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

Title: Re: Button with two functions
Post by: peter81 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
Title: Re: Button with two functions
Post by: BR549 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
Title: Re: Button with two functions
Post by: stirling 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
Title: Re: Button with two functions
Post by: peter81 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.
Title: Re: Button with two functions
Post by: peter81 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
Title: Re: Button with two functions
Post by: peter81 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
Title: Re: Button with two functions
Post by: stirling 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 (http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160)

Ian
Title: Re: Button with two functions
Post by: peter81 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 (http://www.machsupport.com/forum/index.php/topic,15120.msg101160.html#msg101160)

Ian

Thanks Ian now it's working.

Peter
Title: Re: Button with two functions
Post by: peter81 on August 28, 2011, 02:53:26 PM
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


Can someone take a look at this macropump (stop-pause button). I was thinking to implement this to all of my buttons in my pendant to have more functions, but I can't figure it out how the code works.

Peter