LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sir i have boolean variable i want if mouse is clicked on it and if i click mouse for more than 2 seconds another boolean should become on

sir i know it can be implemented by events but it has not solved problem i have given effort in it.
0 Kudos
Message 1 of 9
(3,576 Views)
An event structure should be able to do this job.

You will also need some code to help out.

One method would be as follows.

Put an event structure in a while loop with 3 shift registers. One Shift register will hold the state of your output boolean. Another shift register can hold a boolean used to track when the change is "Armed" i.e. waiting to be changed. The other shift register will hold the time when the mouse down event is detected for your control boolean.

Use two events, 1 for mouse down, the other for mouse up.

In the mouse down, set the armed boolean true and save the time in the shift register.

In the mouse event, check the state of teh armed boolean flag and subtract the current time from the value in the shift register. Also set
teh armed flag to false.

When the Armed flag is true and the time is more than two seconds, change the state of your output.

This is quickly illustrated in the attached VI. (Note: Neatness does not count:>)).

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 9
(3,576 Views)
Hi,

I am including a vi which solves your purpose.

Hope this works. Your feedbacks are welcome.

Best Regards,
Nirmal Sharma
India
0 Kudos
Message 3 of 9
(3,576 Views)
Event structures are the way to go.
As Ben said, use an event for mouse down and another event for mouse up.
Do you want to check the time only on a mouse up or even before mouse up, while the button is still being help down?
The LabView 6.1 example attached gives you the choice. The LED also goes out the next time you press teh button if it's for less than 2 seconds.
I guess this was a pretty popular question.
0 Kudos
Message 4 of 9
(3,576 Views)
Ben:
I didn't go through your code, but once your LED goes on, it stays on, even if the next time you press the button it's for less than 2 seconds.
0 Kudos
Message 5 of 9
(3,576 Views)
You are correct!

The orignal question was not exaclty clear on what should happen to clear the output boolean.

My example simply toggles the state of the output boolean when the control boolean is held down for more than 2 seconds.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 9
(3,576 Views)
Nirmal:
I think the question asked how to indicate that a button was held down for more than 2 seconds. Your example just lights the LED two seconds after the button was pressed and doesn't check how long the button was held down. To see how long a button is held down, you should use an event structure. Look at Ben's example or my example.
0 Kudos
Message 7 of 9
(3,576 Views)
For those who don't have the ability to create event structures, it's pretty easy to do the old-fashioned way. Create a while loop with a shift register and initialise it with the ms tick count. Each time round the loop, check the Boolean and if it is True, keep the existing shift register value, otherwise update the register with the current ms tick count. Compare the current ms tick count with the original value plus 2000 and if it's greater, exit the loop and write True to the second Boolean. The loop only needs to cycle every 100 ms or so so it's hardly a big drain on your processor...
0 Kudos
Message 8 of 9
(3,576 Views)
There are some limitations to this approach.
The mechanical action of the switch can only be Switch Until Released or Latch Until Released. For any other mechanical action, you can tell when it was pressed or when it was released, but not both. If you need to use local variables for your button, you can only use Switch Until Released (locals don't work with latch actions).
Switch Until Released and Latch Until Released limit the switch to a momentary-contact switch. If you need a toggle switch, you need an event structure.
Using an event structure gives you a lot more flexibility. You can use a toggle switch. You can check if the button was held while turning it either off or on or both.
0 Kudos
Message 9 of 9
(3,576 Views)