LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

joystick get a numerical value different than 0 and 1

Solved!
Go to solution

I am newbie in labview, I only have a few weeks learning by myselft and almost everything that I learned was from here, but I have one question.

 

I would like to store in a array a number of pressed buttons. Any time, I press a button, this will be stored in the array, but the problem is the bool to int conversion, only change ON to 1, so I wont know which button was pressed and also 0 is not usefull. For example,

Button 1 will have a value of 1;

Button 2 = 2;

Button 3 =3;

Button 4 = 4; and so on...

so, If I press once every button, the result should be 1D array indicator of 4 elements:1-2-3-4.

I really appreciate any comment or example that you can provide to me

0 Kudos
Message 1 of 18
(3,505 Views)

Since you are working with boolean array, what do you think about "(boolean) array to number"?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 18
(3,494 Views)

Every button in the joystick is a boolean element, so I would like to assign a numerical value for every button. In my project, I used select to assign a numerical value but I dont know if there are any other different way and more usefull for my purpose that is store its numerical value in order I pressed in the array.

0 Kudos
Message 3 of 18
(3,490 Views)

How are you going to handle multiple buttons being pressed at the same time?

 

Ignoring the multiple button presses for a moment, one option would be to use the Search 1D Array for a TRUE value and increment the resulting index.  So button 1 would be 1, etc. and no buttons pressed would be 0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 18
(3,486 Views)

No, Only one button per time

 

I am trying to recreate a game where you have a 10 random number between 1 to 4. So, After press a sequence of 10 buttons (A, B, X,Y), the program gonna compare the order and if the order is correct, you win.

It is a little game that I would like to recreate about memorize sequences of numbers

I upload a vi file and a picture of the block diagram where only have the button counter, and a comparator of a random array with a array of 1's that i create just to check how to compare two arrays, but I dont have a clear idea about how to create a array of buttons valuesblock diagram.JPG

0 Kudos
Message 5 of 18
(3,484 Views)
Solution
Accepted by topic author fastlater_pro

This probably isn't exactly what you want, but it should get you pretty far.

 

First of all, use the Cluster to Array function to get an array of the buttons pressed (boolean array).  From there, use the Search 1D Array to find which button was pressed.  If a button was pressed (-1 means not found, I incremented the index to make life slightly easier), add it to your array.  I kept a count of number of buttons pressed and the Replace Array Subset so memory wasn't being reallocated.

 

Secondly, right-click on your Equal comparison.  You will find a menu item for Comparison Mode->Compare Aggregates.  This will give you a single boolean since it will now compare the arrays themselves.

 

You really should have a wait in the loop so that it isn't running at full speed (100ms should be good).  Also (just noticed my bug) the Greater? should be Greater or Equal?.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 18
(3,466 Views)

Here is some "comparable" excerpt code to crossrulez code, which enables you to handle simultaneously pressed buttons (if needed):ArrayToNumber.PNG

 

Norbert

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 18
(3,460 Views)

Crossrulz, The program is not storing the button, I think that is the case, I create four case and every case I repeat the same operation. I think that is wrong,

what are the properties of the case structure for this program?

the default case is "use default case if is unwired "?

Capture.JPG

0 Kudos
Message 8 of 18
(3,455 Views)

looks like we'll be seeing a new post on the R-G threadSmiley Very Happy


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 18
(3,453 Views)

@fastlater_pro wrote:

Crossrulz, The program is not storing the button, I think that is the case, I create four case and every case I repeat the same operation. I think that is wrong,

what are the properties of the case structure for this program?

the default case is "use default case if is unwired "?


You really should not have the exact same code in different cases.  You can set the case to be "1..4".  The ".." means a range.  So any number from 1 to 4 will generate that case.  That will help elimate the duplicate code.

 

I don't know where you are getting the "use default case if is unwired".  The way the default works is if none of the other cases are satisfied, the default is called.

 

How do you know the button presses are not being stored?  You might want to move the Buttons Pressed indicator inside of the loop so you can get an update as you loop through.

Ahhh, I just noticed that your initial array is empty.  Set the index to 9 and type 0 in the array.  That will initialize your array to 10 elements.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 10 of 18
(3,447 Views)