12-27-2011 10:42 AM
What mechanical action is recommended for a button used in an event structure?? Right now I have "Latched when pressed" but I've noticed when the user pushes the button it latches and returns to its original position so fast the user doesn't even know it was pushed. Other times ( I have a lot of stuff going outside the event once the button is pushed) I notice the button stays depresed for several seconds then returns to its defaulted position. I've tried other mechanical actions but they seem to stay depressed even after the user pushed them and the event is exe 2xs. All I want is to have an event executed 1x, the button to show that it was pressed then return to the original position. Previous suggestions were to put an "led"on the button to indicate it had been pressed but I have 18 buttons and if possible would like to stay away from that solution..if possible.
12-27-2011 10:54 AM
You could use a switching button and use the boolean text to indicate the state. You could use a property node connected to the CtlRef node to do other things like change the color of the button programatically.
12-27-2011 10:54 AM
(The button will return to the default state after it has been read by the code. This could be immediately to never, depending on the dataflow.)
You could do "latch when released" instead. This way the button remains depressed until the user releases it, at which point the event triggers.
12-27-2011 04:59 PM
All my booleans are Latch when Released or Switch when Released. When coding my events, I generally use Switch when Released and then, at the very end of the event, reset the button to the default value with a local variable, property node, or shift register, depending on the situation. This way, the user has visual feedback of when the event is running and when it finishs.
12-27-2011 10:36 PM
Switch when released give you control on popping the button up. Unlike Switch when pressed, it will avoid race condition with keyboard and or the OS. Try to control the response time with a wait of 300, 200 or 100 msec, typical times. Or just leave in the position till the action is complete then pop the button back.
12-28-2011 05:59 AM
Doesn't an Event Structure wait for something to happen ( button presed and 'value change') to do something?????? My understanding is if I select the correct button action when I press it the event will be kicked off, the button will return to its default condition then the event structure is monitored again. Why do I need to reset the button. I guess what I'm looking for is a momentary software button. You push it, it stays depressed long enough for the user to know he/she pressed it, the event happens then the switch/button returns to its original position. I don't understand why I have to reset it. Is there not a button to do what I described??
12-28-2011 06:14 AM
Put the terminal of the button inside the event where you are monitoring and keep the action as latch when released.
By this system will read the current value of the button atleast once.
12-28-2011 11:11 AM - edited 12-28-2011 11:16 AM
@MarkDavid wrote:
Doesn't an Event Structure wait for something to happen ( button presed and 'value change') to do something?????? My understanding is if I select the correct button action when I press it the event will be kicked off, the button will return to its default condition then the event structure is monitored again. Why do I need to reset the button. I guess what I'm looking for is a momentary software button. You push it, it stays depressed long enough for the user to know he/she pressed it, the event happens then the switch/button returns to its original position. I don't understand why I have to reset it. Is there not a button to do what I described??
You only have to reset it in one of the switching modes if you need latching behavior. You do not have to reset it in any of the latching modes because reading the terminal will cause an automatic reset. You cannot use local variables or value properties for latching or you get an error. Sometimes people will simulate latching when they need to use local variables by setting mechanical action to switching then writing back to it with a local.
The differences are when the value actually changes and when value change events actually fire. For example switch when released causes the value to change (and event to fire) when you let go of the button. The user can change their mind. For example they can click and hold the button. If they move the mouse away from the button before releasing the mouse then the event will never happen.
Both the switch until and latch until released modes will cause two value change events to fire.
The easiest way to understand them is with a simple demo. The attached vi has six buttons for the different mechanical modes. There is a value changed event for each and an indicator for each. Because the latching modes will reset so fast that you cannot see the indicator blink I put a delay in the event structure for those.
Play around with this and take note of the LED activity for each button. Also look at the number of events indicator. After playing with this for a while it should become clear.
[Edit: I think the button action you want is Latch Until Released or Latch When Released. The "until" released will cause two events to fire. Put your code in a case structure and connect the selector to the latch until released button.]
12-28-2011 11:25 AM
One more thing. I think if you modify the event case for latch when released as follows it should do exactly what you want.