LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Case Structures with momentary switches

Solved!
Go to solution

I found this example in the NI Example Library, and am bending the concepts to my use. In my application the Case Structure wanted a default Case, so I gave it Zero. The push button switches when not depressed cause the case structure to flip back to zero. I would like the Case Structure, when it see's a 1 to stay there until another button is pushed and then stay there, etc. I don't know if I want to turn a numeric instance into a ringing number or keep the Case from changing unless it see's an integer change. Ideas?? Hopefully the attached png shows up.

Thanks Dan

0 Kudos
Message 1 of 13
(3,293 Views)

Make a separate default Case that does nothing.  Have the 3 individual cases for 0, 1, and 2 so something.

 

When no buttons are pressed, the Search 1D array will return a value of -1.  Since you don't have a specific -1 case, it will return the default case which you happened to code up to be the same as the 0 case.

 

EDIT:

Actually. you kind of already took care of that since you added 1 to the search output so 0 will mean no choice, and 1, 2, 3 will be specific choices.

 

So exactly how is your VI not doing what you want it to do?

0 Kudos
Message 2 of 13
(3,271 Views)

Hi Dan,

 

I would expand this upper shift register first, then using the Comparison Pallete, I'd compare if the third last button selected (the new shift register of the left side) is equal the actual button, if true the input of the shift register of the "Last Button selected" would recieve the "Last Button selected" delayed (second last button selected), if false it would recieve the the actual one.

 

Best Regards,

Iago

0 Kudos
Message 3 of 13
(3,244 Views)

@Hobbs23 wrote:

I would like the Case Structure, when it see's a 1 to stay there until another button is pushed and then stay there, etc.

Just use a radio button control and wire it to the case structure. Almost no code needed.

Message 4 of 13
(3,234 Views)

Well, and there is the rub. Whichever case structure was selected, needs to stay face up and monitor knob movements and other things on the front panel that may be happening. Each case structure will provide a different panel interface for the user. If it keeps flipping back to zero then I will have to do event or notification to switch back or something. I don't know how to do that stuff yet, and LabView 2009 doesn't have some of the more modern event handling goodies for me to want to learn.

0 Kudos
Message 5 of 13
(3,191 Views)

Why does the button need to pop back up?  Why not let it stay down until another button is pressed?

0 Kudos
Message 6 of 13
(3,188 Views)

I will try***added "The Radio Button"*** as well. Although I am not sure he would like the look of it visually. It might be like purchasing the standard variety argument from him. 🙂

 

*** Sorry I forget these replies don't attach to who you are replying to.

0 Kudos
Message 7 of 13
(3,187 Views)

Having the button stay down until the next one is selected is what I originally tried. What I ended up with was the action to clear the old button that had been pressed, needed to be momentary, otherwise your button press already has a command to not allow it hanging there. I tried using flip flops, or Master Slave Latches, timers etc. to have the switch reset just be done. In the while loop It would do what I wanted and then cycle it back on again.

0 Kudos
Message 8 of 13
(3,181 Views)

I will also try expanding the Shift Register and doing some logic work there as well. I don't know why Programming insists that I make a default Case! I wish it would just leave it where I left it until I change it again.

0 Kudos
Message 9 of 13
(3,176 Views)

@Hobbs23 wrote:

I will also try expanding the Shift Register and doing some logic work there as well. I don't know why Programming insists that I make a default Case! I wish it would just leave it where I left it until I change it again.


Because if you have a datatype such as an integer with an infinite number of possibilities.  (Well, not infinite, but a very large number), what case should run, what output should there be if the value isn't one of a handful of numbers you assigned a value to?  If you have a datatype with a finite number of possibilities (boolean, enum) you don't need a default case, unless you haven't defined a specific case of each possibility.

 

What is wrong with having a default case that "would just leave it where I left it until I change it again"?  If you keep the current value in a shift register, then the default case can continue to pass the current value through to the shift register until a different case occurs to change it.

 

Have you taken LabVIEW tutorials and learned about dataflow?  It feels like you are trying to force LabVIEW to execute in some preconceived notion that you have rather than learning how to work with it.

Message 10 of 13
(3,170 Views)