11-03-2013 03:35 PM
Hello,
I want to have three constants in an array and when a button is pressed the point of the array will move one position up. Also I want to display, output this value to a numeric indicator each time the button is pressed. I'm new in Labview and I'm not sure if is too complex to do it. Thanks for the help.
Solved! Go to Solution.
11-03-2013 03:43 PM
Use a while loop. Add a shift register. The button connects to a case structure selection terminal. Inside the true case you index the array and then increment the index value which is saved in the shift register. The loop should also have a Wait(ms) function so that it does not spin millions of times each second. A wait of ~100 ms is a good place to start.
Because you are new to LV, I described one method but did not present you with a complete VI. You will learn more by trying to do it yourself.
If you have not had a training class, look at the on-line getting started tutorials. Also, keep the Context Help window open while programming. It tells you a lot about the particular item under the cursor.
Lynn
11-03-2013 03:52 PM
Thanks johnsold! I will try that and see how it goes. I will reply later if I managed to do it or not 🙂
11-03-2013 05:25 PM
This is what I did! Although I get an error which says "case structure: No case for some selector values". I removed the false condition from the biger case structure and is only the true condition. I don't know what is the problem...
11-03-2013 06:04 PM - edited 11-03-2013 06:04 PM
Please attach the actual VI instead of pictures. Thanks!
You code makes no sense. In the shift register you are randomly mixing array values and array indices. Your indicator is after the loop, thus it will not update until the stop button is pressed. We cannot tell what is in the other cases. If a case structure has only one case, you might as well delete it, because it has no function.
11-03-2013 06:06 PM
chis20 wrote:I want to have three constants in an array and when a button is pressed the point of the array will move one position up. Also I want to display, output this value to a numeric indicator each time the button is pressed.
What should happen if you are at the third (highest) position and the button is pressed?
11-03-2013 06:14 PM
Thanks altenbach for the reply! If is in the highest position I want to go back to the start, 0. That's why I check whether I get a number greater than 2. If is grater than two I say to give -1 and by adding +1 to become 0.
I will try to update it now given your previous response!
Chris
11-03-2013 07:04 PM
This is what I did until now. Now I know that I can loop through the array
My problem now is that I don't know how to add an event to the button so to change value only if it's pressed. I don't care if is true or false. Anytime I press it I want to display me the next value from the array and wait until I press it again.
11-03-2013 07:17 PM
Well, create an event structure for the button.
Make the button latch action, so it always reset to false once the code reads the new value.
(Or simply use another case structure instead of an event, because a latch action boolean is always true when just operated and false otherwise)
There is a "+1" primitive.
Instead of the inner case structure, you could use quotient&remainder to wrap around after the third element.
11-04-2013 10:29 AM - edited 11-04-2013 10:32 AM
Did it!! Thanks altenbach!! Also I changed the inner case structure with quotient & remainder - much simpler!
I'm a noob here...do I have to accept a solution from the previous messages?