# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Calculation of Time a Button has remained ON

Dear All,
I want to calculate the ON time of a button and for this purpose i am using Timed loop, case structure and a button. The problem is when i press the button, the timer starts and indicator gets updated But when i turn the button OFF, it does not stop the timed loop. I am attaching the screenshot of the schematic. Please guide me in this regard,
Thanks in anticipation.

Message 1 of 7
(887 Views)

## Re: Calculation of Time a Button has remained ON

You could do this easily with an event structure.

Look for a value change event on the button. Store the time each time its triggered (either feedback node or shift register).

If the new value is false, subtract the previous time from the current time and you have the ON time.

Message 2 of 7
(871 Views)

## Re: Calculation of Time a Button has remained ON

Times are typically measured, not calculated.

Your snippet seems incomplete and broken. Why is there a local variable? Why is there no top-level loop? What's the mechanical action of the button? Are you using "continuous run" mode?

(Sorry, posting by phone, cannot run).

Message 3 of 7
(868 Views)

## Re: Calculation of Time a Button has remained ON

You can do this by using Tick, call it every time the button is on then again when is off, then calculate the difference.

Message 4 of 7
(850 Views)

## Re: Calculation of Time a Button has remained ON

@LVNinja wrote:

You can do this by using Tick, call it every time the button is on then again when is off, then calculate the difference.

I recommend "high resolution relative seconds" instead. Time will be in seconds instead of milliseconds.

Message 5 of 7
(843 Views)

## Re: Calculation of Time a Button has remained ON

@deceased wrote:

You could do this easily with an event structure.

Look for a value change event on the button. Store the time each time its triggered (either feedback node or shift register).

If the new value is false, subtract the previous time from the current time and you have the ON time.

One potential problem with that is if the button happens to be TRUE when the program starts. (not a problem in a build applications, though).

Message 6 of 7
(789 Views)
Solution
Accepted by topic author RaoJaved

## Re: Calculation of Time a Button has remained ON

Here's what I might do. (modify according to the requirements, of course).

Message 7 of 7
(786 Views)