LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling an Array when pushing a button : issues

Solved!
Go to solution

Hello,

In my small code (jointed), I am just trying to fill an array in an event loop and I have two issues :

 

Problem 1 : I don't understand why, but only the first value of the array is filled, and always replaced by the new value, this is not what I want. I want to fill the array completely successively

 

Problem 2 : I want to fill it continuously as long as the button is switched. In my code, for a reason I don't understand, the array is filled just one time, even if the button stay pressed.

 

(Problem 3 : I will need to get the time in seconds since the button is pressed in the array, is this doable ?)

 

Thanks so much if someone can help. This is no homework, I am trying to do automation work at home, am a bit a newbie in Labview and I will need that code

0 Kudos
Message 1 of 6
(1,688 Views)
  1. You write to a new different array ("array supposed to be filled") and always start with the same old array ("array")
  2. You have an event structure on "value changed" if you hold down the button, the values does not continually change.
  3. Yes, it is doable.

All you need in an indicator and a shift register initialized with an empty array and where you append new values as long as the switch is true. No need for an event structure. Change the button mechanical action  to "switch until released" so it is true as long as you hold it down.

 

0 Kudos
Message 2 of 6
(1,664 Views)

A button press handled by an event structure will happen once. If this is all your program needs to do I would get rid of the event structure and just just have a while loop with a small wait inside it (see attached). If more needs be handled by your program you may want to keep the event structure and you will have to figure out some other way to deal with the "while button is pressed, do x" logic.

 

Notice that in the attached vi I changed the mechanical action of the button to "switch until released"

 

(Forums LV2017)ExampleFillingArray.png

0 Kudos
Message 3 of 6
(1,653 Views)
Solution
Accepted by Oxbow8

The wait already gives you the tick count that you can use for the timer, here's all you need. Just convert ms to s for display.

 

altenbach_0-1596519607979.png

 

 

(I assumed that you want to start the timer from zero with every press, then reset when the button is released. If you want different behavior, that would be easy to change)

Message 4 of 6
(1,629 Views)

thanks so much it is working well !!

0 Kudos
Message 5 of 6
(1,582 Views)

Be aware that if you plan to hold the button down for more than ~50 days (4294967295ms), the U32 will wraparound and the duration will start from zero. If this is of concern, you could use one instance of the high-resolution relative seconds instead of the wait output. Remaining code is the same. 😄

0 Kudos
Message 6 of 6
(1,576 Views)