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.

# LabVIEW

cancel
Showing results for
Did you mean:

## Counting down to zero from a specified number

I'm sure this is a very simple thing to do, but I can't figure out how. I want to count down from a specified number to 0, then restart counting at that orginal number. The trick is that I need it to place it in a case structure, and have it restart counting when it switches states (i.e. from TRUE to FALSE and vice versa).

Example: Say I want to count down from 2 (as specified in a constant). Should look like:
FALSE
2
1
0
2
1
0
2
---TRUE
2
1
0
2
1
---FALSE
2
1
0
2
1

I'm sure this is easy to do, but I've been wracking my brain!

Thanks!
-Brendan
Message 1 of 10
(3,061 Views)

## Re: Counting down to zero from a specified number

Brendan,

The attached VI is the simplest example I could think of. By default, it counts down from 10. It's saved in LabVIEW 7.0. Hope this helps.

Steven H.
Message 2 of 10
(3,052 Views)

## Re: Counting down to zero from a specified number

While I don't know what you mean by "when it switches states", I have attached one solution using an event structure. Here "it" is simply a boolean control that switches states under operator control.

See if this makes sense to you.
Message 3 of 10
(3,042 Views)

## Re: Counting down to zero from a specified number

Thanks for your help. Anyway I could get this in Labview 6.1 format (or let me know how to open it in 6.1)?
Thanks so much,
Brendan
Message 4 of 10
(3,015 Views)

## Re: Counting down to zero from a specified number

Here's Altenbach's VI in 6.1.

___________________
Try to take over the world!
Message 5 of 10
(2,977 Views)

## Re: Counting down to zero from a specified number

Okay, this looks good. I like the event structure's ability to detect a change of state. Here's the problem though: in the examples given, the event structure is always used to detect an action by the user, usually though a boolean control. What I need is a way to trigger the event using a boolean value *internally* generated. I tried just creating a boolean indicator and using that, but it doesn't seem to work. I'm SO close to getting this to work, but I need a way to have the event strcture poll the status of an internally generated boolean value (as opposed to one controlled by the user through the switch in the example).

Thanks!
-Brendan
Message 6 of 10
(2,940 Views)

## Re: Counting down to zero from a specified number

You need to create a property node. Right click on the control or the terminal and select Create>>Property Node. Then select the Value (signaling) property. This will trigger the value change event.

___________________
Try to take over the world!
Message 7 of 10
(2,934 Views)

## Re: Counting down to zero from a specified number

Where is this value signaling property? I create the property node, then how do I select the signaling property? I'm running LV 6.1 - does that make a difference? If I happen to find it, once I select it that's all I have to do, and my event structure will trigger off the boolean value?
Thanks a lot for your help.
Message 8 of 10
(2,927 Views)

## Re: Counting down to zero from a specified number

You are correct in that that is all you have to do, but the fact that you're running 6.1 makes all the difference - that property didn't exist yet. If I remember correctly, dynamic user events weren't available either, so you can't fire an event programmaticaly. Try searching the site for "6.1 event programmatic" or something similar to find alternate solutions (like a queued task handler).

___________________
Try to take over the world!
Message 9 of 10
(2,920 Views)

## Re: Counting down to zero from a specified number

Great. I got it up and running. I used the event handler 'timeout' function to check periodically if the timer had counted all down and reset it, then I just used nested case structures with shift registers to keep track of boolean state changes. I really appreciate all your help!

Thanks a lot!
-Brendan
Message 10 of 10
(2,896 Views)