08-29-2022 03:28 AM - edited 08-29-2022 03:30 AM
Hello everyone, here I have a problem.
I want to make a button, where when the button is pressed (active/true) it will count.
I tried using two types of buttons, OK button and Boolean, to see the difference. For more details see the attached image.
the problem is whether can the button labeled Boolean do the calculation like the OK Button.
Please help sir, I'm new to labview programming. Thank you
Solved! Go to Solution.
08-29-2022 05:07 AM
Hi Oto,
@MangOto wrote:
the problem is whether can the button labeled Boolean do the calculation like the OK Button.
Please help sir, I'm new to labview programming. Thank you
When you are new to LabVIEW then you should take those Training resources as offered at the header of the LabVIEW board.
On your question: learn about the different mechanical behaviours of those buttons! (switching vs. latching…)
On your VI:
why do you need to count using a floating point value? Wouldn't an integer do the same job more nicely?
08-29-2022 10:50 AM - edited 08-29-2022 10:56 AM
Thanks for the suggestion sir, I already understand the difference between toggle button and lock.
Based on the VI I made, I used two buttons.
1. The one labeled Boolean will operate the switch when pressed.
2. The Ok button operates the latch when pressed.
When viewed in Labview operations. My goal is to make the Boolean button work the same as the OK button. If it is true then it is worth 1 if false the value is still 1, if the "Boolean" button is pressed again or is true then the value to be shown will increase to 2 and when false it will still be worth 2 (will increase by 1 if it is true).
I don't have any ideas, sir, can you give me a solution for this problem? I will be very grateful if you provide assistance.
and thank you sir for the comment too
08-29-2022 02:34 PM
Hi Oto,
@MangOto wrote:
My goal is to make the Boolean button work the same as the OK button.
Then you should set them to use the same mechanical behaviour...
08-30-2022 07:24 AM
Gerds gave you the neatest solution for your question. This comes from the additional behavior LabVIEW implements into the boolean switch, when you set the mechanical behaviour to latched. The "properties" dialog illustrates this very good.
But there are two ways you would implement this latched behaviour yourself. The one (worse) solution is to compare for every loop cycle the current state of the bool with the state of the previous cycle (use a shift register to store the previous state) and increment the counter only if the states are different and the current is TRUE.
The second (better) way is to use an event structure. And this is all the way better than polling the switch all the time, epecially since you don't use a wait timeout.
08-30-2022 08:41 AM
@MangOto wrote:
Thanks for the suggestion sir, I already understand the difference between toggle button and lock.
Based on the VI I made, I used two buttons.
1. The one labeled Boolean will operate the switch when pressed.
2. The Ok button operates the latch when pressed.
When viewed in Labview operations. My goal is to make the Boolean button work the same as the OK button. If it is true then it is worth 1 if false the value is still 1, if the "Boolean" button is pressed again or is true then the value to be shown will increase to 2 and when false it will still be worth 2 (will increase by 1 if it is true).
I don't have any ideas, sir, can you give me a solution for this problem? I will be very grateful if you provide assistance.
and thank you sir for the comment too
The OK button and the boolean button are both boolean buttons with different mechanical actions. Just set the mechanical action the same and use the same code.
08-30-2022 09:16 AM - edited 08-30-2022 09:25 AM
If your goal is to make the first loop act like the second you need to program it the same. Even if you use the same mechanical action for your buttons you will not see the same behavior since the code is different. We can't see what's in the other cases but in your first loop you have the Select function set up to toggle between a 1 and 0 based on the boolean switch. Your wiring is messy so we can't even see which is selected but it looks like you can only toggle between 1 and 0. You will never count up past that even if the false case has an increment.
Why did you code two different things if you want the same behavior?
EDIT: Forgot to mention that you should put a Wait VI in the loop to prevent the loop from spinning so fast it consumes all your CPU cycles. Put a 25mSec wait in there and then you will see that when you use a latch method it increments by 1 on each click and when you use a switch method it will keep incrementing 40 times per second when the switch is TRUE.
EDIT2: DaveTW is right about the event structure option. It is designed for this kind of thing and is the best way so look into it after you understand the way you're doing it now.
08-30-2022 09:42 AM - edited 08-30-2022 10:15 AM
In summary:
Here's a more elegant solution and probably all you need. At your state of learning, I would avoid the event structure. that comes later.
09-01-2022 12:32 PM
thank you very much sir for your help