From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-06-2022 08:03 AM - edited 06-06-2022 08:06 AM
Hello,
I am new to LabView and I am really struggling toggling between states when a button is pressed. The state should only change once per button click. and the state should remain until the next button click. I tried it with an additional register which holds a boolean whether the state was changed and if yes set it to false if the button was released but it is not working and super complex. You find the basic setup in the VI I uploaded. How would I achieve the desired behavior? Do I really have to manage multiple variable in order to check whether the state was already changed?
Additionally, how would I wait in the inactive state for the next button click to change the state so that there are no unnecessary loops. I am really struggling for some time but nothing works + it is just messy trying to manage multiple shift registers to really only change once per button click (pressed).
I would appreciate any help!
Solved! Go to Solution.
06-06-2022 08:19 AM
Just use a button with the Mechanical Action set to Switch When Pressed. Then you can just wire the sensor straight to the case structure.
06-06-2022 08:24 AM - edited 06-06-2022 08:26 AM
Thank you for your answer. I am trying to simulate hardware interactions. There is a touch sensor which has three options: released, pressed and bumped. That is why I have to use either released or pressed in order to correctly simulate the behavior since I currently have no access to the hardware. How would I do that if the only options were really released or pressed events?
06-06-2022 10:09 AM - edited 06-06-2022 10:09 AM
So it is very complex when having only the options released and pressed? Do you have any approaches how to manage state change with those two options?
06-06-2022 10:50 AM
If you want to switch a LED whenever a latch action button is pressed, here's what you can do. try it!
06-06-2022 12:26 PM - edited 06-06-2022 12:29 PM
Thank you for your answer. It is not a latch action button. In fact, it is the touch sensor button of a Mindstorm Ev3 robot. I try to implement switching cases whenever the touch sensor was pressed. That is why in my setup the button had switch until released as the operation to simulate that behavior. That is why I cannot change the button behavior as you did. So is there any other solution to my problem given the above explanation of why I can't use different button actions? The touch sensor of the robot has three options: pressed (returns the value 1 as long as the button is pressed and 0 if released), released (returns the value 1 as long as the sensor is released and 0 if the button is pressed) and bumped (returns the value one for a short period of time when the sensor was pressed and then released). How would I simulate the desired behavior and correctly switch between the cases once when the sensor was pressed? I dont have access to the robot right now but want to implement the switching between the stages by simulating the touch sensor.
06-06-2022 12:37 PM
Sorry, I was not able to look at your code (LabVIEW 2021).
"Switch until released" does not guarantee that the button is read by the code, for example if you release it before the terminal actually gets read.
06-06-2022 12:46 PM
06-06-2022 01:23 PM
Thank you! It works fine. I append a screenshot to this post so that you can see how it should work. Could you tell me whether it would be possible to wait in the inactive state until the next change to the active state (true case) so that the loop does not unnecessarily continue?
06-06-2022 01:32 PM
Well, you need to "loop" the loop, else the terminal never gets read again.
You don't need a case structure, of course. Make the code more readable!