LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch between 3 specific values on button press

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 15
(4,362 Views)

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

0 Kudos
Message 2 of 15
(4,357 Views)

Thanks johnsold! I will try that and see how it goes. I will reply later if I managed to do it or not 🙂

0 Kudos
Message 3 of 15
(4,353 Views)

This is what I didAlthough 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...

Download All
0 Kudos
Message 4 of 15
(4,331 Views)

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.

0 Kudos
Message 5 of 15
(4,317 Views)

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?

0 Kudos
Message 6 of 15
(4,310 Views)

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

0 Kudos
Message 7 of 15
(4,305 Views)

This is what I did until now. Now I know that I can loop through the array Smiley Tongue 

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. 

0 Kudos
Message 8 of 15
(4,287 Views)

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.

0 Kudos
Message 9 of 15
(4,277 Views)

Smiley Happy Smiley Happy Did it!! Thanks altenbach!! Smiley Happy 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?

 

0 Kudos
Message 10 of 15
(4,217 Views)