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
Solved! Go to Solution.
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.
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"
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.
(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)
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. 😄