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 
Search instead for 
Did you mean: 

Counting a button push

Solved!
Go to solution

Hello Everyone,

 

I am trying to learn to use LabView and it is going pretty well so far.I have a Vi that will read in strain gauge values (right now it just has some dummy variables so i can test it without having it all hooked up) then does some engineering stuff to it and in the end I have it writing to an excel spreadsheet and saving a Jpeg of the graph made. Well i have been trying for a few days now to make a counter that will increase when I hit the "record" button. I then want to use that counter to index the file name I save the Jpeg under (haven't gotten to this yet). I've my VI in a zip becasue it has some other VI's attached inside But the main one is Strain Gauge.VI. Any hep you guys could give would be great!!

Thank you,

A Student Learner

0 Kudos
Message 1 of 9
(4,429 Views)
Solution
Accepted by topic author D3V3R

You should learn about shift registers (or feedback nodes) to keep count. Initialize with zero and just increment the value when ever the latch action button is true. There are plenty of examples in the forum to count button presses.

 

Here is one possible way (assuming the button is latch action).

 

CountPresses.png 

 

You can also use them (i.e. shift registers) for your zeroing. No need for all these local variables (a1, a2, a4). Writing to a terminal and a local variable of that same terminal in parallel is redundant and shows a basic misunderstanding of locals. You also have a race condition because currently reading the locals occurs in parallel to the writing and while the outcome differs depending on the order, the order is not defined. Also it would be easier to keep the zero reference as an array with three elements, simplifying the code.

 

What exactly determines your loop rate and where does the new data come from?

0 Kudos
Message 2 of 9
(4,403 Views)

Shift registers! I have seen them around the forums I just never really understood them so I will do some more reading and learning about them. As for the first half of the program, it currently works so I am not going to mess with it for now but later I will try and clean it up.

 

The new Data will come from a DAQ Assist but I am working on this outside of class where I dont actually have the strain gauges to feed in numbers. That's the reason for the dummy variables at the left most side of the VI.

 

Once I get the button to work is creating a file name with that "count" hard?

 

Thank you for your response!

0 Kudos
Message 3 of 9
(4,375 Views)

@D3V3R wrote:

 

Once I get the button to work is creating a file name with that "count" hard?

 


No, it's just a formatting operation to create the file name, followed by "build path" to add the file location.

 

Did you look at the image I added to the earlier posts?

0 Kudos
Message 4 of 9
(4,370 Views)

Yes I did and I plan on testing it later today when I have break from class.

Again thanks for your responses!

0 Kudos
Message 5 of 9
(4,364 Views)

Okay so I am sitting here drawing a blank... What is the green structure in your image and how does it connect to the button?

0 Kudos
Message 6 of 9
(4,357 Views)

The only green thing is the button terminal (maybe you are used to see them as icons? same thing!) and the green wire. The next node is "boolean to (0,1)".

0 Kudos
Message 7 of 9
(4,350 Views)

Hey man I had just figured it out right before you replied! I have the counter and the file out put all set up now and everything is working great. I uploaded it again just so you can see the final result. Of course I have TON of cleaning up to do and then taking into consideration what you said about the zeroing function but for now it will do what I need it for LAB tomorrow!

 

Thank you So much for your help!

A slightly more informed student learner.

0 Kudos
Message 8 of 9
(4,346 Views)
  • Your counter indicator should not be U64, seems excessive. (Try I16 or I32)
  • X3 Should be DBL, not EXT.
  • I told you to use build path. (treating paths as strings and using string to path breaks the code on other platforms (mac, linux, etc.))
  • You can do the entire filename with one format (formatting a floating point number as %d will drop the decimals, not sure if you want that. For the sequence number, you should do zero-padding (e.g. %05d) so alphabetic sorting of the files will keep them in numerical order.

Here are some ideas to get you started:

 

simplifications.png

0 Kudos
Message 9 of 9
(4,340 Views)