LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure-struggle

Solved!
Go to solution

Hi, I am relatively new to Labview, For the project I am working on I have a 4x4 matrix keypad and an arduino, I have it set up so based on each button that i press i receive a different voltage level. i know its not the most efficient way but it allowed me to use only a single analog input from my arduino. What im struggling with is how to differentiate between the different voltages using case structures. 

 

Any type of help would be appreciated, 
I am very new to this NI community so i apologize in advance if I am not following some type of etiquette. 

 

 

Thanks ! 

 

0 Kudos
Message 1 of 11
(616 Views)

@rz19 wrote:


I am very new to this NI community so i apologize in advance if I am not following some type of etiquette. 


Well we can not troubleshoot code that we can not see.

 

Attach your VI to a reply and describe what you are having trouble with. 

 

But I believe the "In Range and Coerce Function" is going to be your friend...

========================
=== Engineer Ambiguously ===
========================
Message 2 of 11
(610 Views)

awe shoot, sorry about that, 

 

This is what I have so far, 

 

Im struggling with the setup of the case structure. I tried reading up on the functions of it, but i cannot figure out how to apply it in my situation. 

 

Thanks in advance.

0 Kudos
Message 3 of 11
(603 Views)
Solution
Accepted by rz19

How about something like this?

 

Secase.png

 

There's probably other ways but this was the first thing I thought of...

 

 

========================
=== Engineer Ambiguously ===
========================
Message 4 of 11
(568 Views)

Hi RTSLVU,

 


@RTSLVU wrote:

There's probably other ways but this was the first thing I thought of...


What about an "array of InRange" functions?

Like this:

It's not an exact replication of the functionality, but can be improved for that purpose.

(I just took your snippet for inspiration as I cannot open the VI of the OP.)

Best regards,
GerdW


using LV2016/2019/2020 on Win8.1/10+cRIO
Message 5 of 11
(550 Views)

Isn't that (at least almost) the same as:

Double to bit.PNG

Of course if so then the x2^n is redundant, as the case structure can simply check 0,1,2,3,4,5 in stead of 1,2,4,8,16,32.

 

I guess we'd need to know what you're trying to do.

Message 6 of 11
(542 Views)

wiebe@CARYA wrote:

Isn't that (at least almost) the same as:

Double to bit.PNG

Of course if so then the x2^n is redundant, as the case structure can simply check 0,1,2,3,4,5 in stead of 1,2,4,8,16,32.

 


But the values the OP had for each case were not integers (0-1, 1-2, 2-3, 3-4) but doubles that has decimal places (3.27-3.68, 3,68-3.92) My example just happened to work out that way because it was simple.

 


wiebe@CARYA wrote:

 

I guess we'd need to know what you're trying to do.


@rz19 wrote:

For the project I am working on I have a 4x4 matrix keypad and an arduino, I have it set up so based on each button that i press i receive a different voltage level. i know its not the most efficient way but it allowed me to use only a single analog input from my arduino. What im struggling with is how to differentiate between the different voltages using case structures. 

 


Basically the OP wants to select a case based on a (DBL) numeric value.

========================
=== Engineer Ambiguously ===
========================
Message 7 of 11
(521 Views)

Hi,

 


@RTSLVU wrote:
Basically the OP wants to select a case based on a (DBL) numeric value.

Then let's go the ThresholdArray way…

Best regards,
GerdW


using LV2016/2019/2020 on Win8.1/10+cRIO
Message 8 of 11
(517 Views)

Sorry, I currently don't have access to LabVIEW 2021, so I cannot see your attached code. Consider "save for previous" before attaching! Thus I have to go with your description:

 


@rz19 wrote:

For the project I am working on I have a 4x4 matrix keypad and an arduino, I have it set up so based on each button that i press i receive a different voltage level. i know its not the most efficient way but it allowed me to use only a single analog input from my arduino. What im struggling with is how to differentiate between the different voltages using case structures. 


Can you press only one button at a time (16 possibilities + none) or are all possible combinations of 0..16 simultaneous presses allowed (2^16 (65536) possibilities!). How many bits are in your analog input? Most likely, the second option is not even possible. Is this a ready-made button matrix with defined output or your own wiring? If only one button is allowed, how do you detect & reject simultaneous presses?

 

As others have already said, why do you focus on "case structure" in the subject line if the problem really has nothing to do with one. It is typically much better to explain what you want to do, not how you want to do it.

 

0 Kudos
Message 9 of 11
(502 Views)

@GerdW wrote:

Hi,

 


@RTSLVU wrote:
Basically the OP wants to select a case based on a (DBL) numeric value.

Then let's go the ThresholdArray way…


Another way would be to subtract the center values, and then get the minimum value:

Closest value.png

0 Kudos
Message 10 of 11
(497 Views)