LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple question about controlling LED indicators with left and right arrow keys.

Solved!
Go to solution

Let's just suppose you want to control 5 led indicators using two buttons "left" and "right" just like the screenshot that I have uploaded. You want the middle one to be light up at first then for example if you press right button, then the middle one just goes off and the right next to it, lights up. Preferably, key binding each of the buttons to the right and left arrow on the keyboard. How would you do that?

0 Kudos
Message 1 of 9
(1,268 Views)

You need a event driver state machine to do such thing.

 

  • Use a event structure within a while loop
  • Add value change events for the left and right buttons
  • Initialize a boolean array of size 5, set the index-2 as True
  • Based on the button changed, do a logical shift (right or left) on the array and display the values using the LEDs
  • Keep track of this array value in a shift register in the while loop (this way any changes is with respect to the previous state)
Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 9
(1,253 Views)

@Seiryuu90 wrote:

Let's just suppose you want to control 5 led indicators using two buttons "left" and "right" just like the screenshot that I have uploaded. You want the middle one to be light up at first then for example if you press right button, then the middle one just goes off and the right next to it, lights up. Preferably, key binding each of the buttons to the right and left arrow on the keyboard. How would you do that?


The easiest is to change your LEDs to an array of LEDs. Initialized it to 00100, then use either a timed loop or event structure and Rotate array when one of the buttons are pressed. How to bind a key to the button? Button Properties.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 9
(1,226 Views)

@santo_13 wrote:
  • Based on the button changed, do a logical shift (right or left) on the array and display the values using the LEDs

How do I do that?

If you could make sample, would be grateful please.
Also, why does auto indexing an array inside a while loop gives me error but a for loop does not? How to fix it

?buttons.png

0 Kudos
Message 4 of 9
(1,210 Views)

 You can resolve this by this way :

Controlling Led Indicators.png

 

Loïc.

Message 5 of 9
(1,204 Views)
Solution
Accepted by topic author Seiryuu90

Few Modifications

 

1. 3rd element is True by default

2. The order of Cluster is changed to avoid array reversing and readability

3.You can use -1 instead of Rotate 1D array to Left Shift.

4. Also, I guess it should limit Movement once it reaches its extreme right/left

 

ReorderArray.png

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 6 of 9
(1,175 Views)

It is very nice of you guys to do the homework for the OP. Unfortunately, they will not learn LV that way. 😁

---------------------------------------------
Certified LabVIEW Developer (CLD)
0 Kudos
Message 7 of 9
(1,165 Views)

Trust me I'm learning just fine thank you for your concern. Goodnight.

0 Kudos
Message 8 of 9
(1,156 Views)

Thank you and Loic much for your help.

0 Kudos
Message 9 of 9
(1,149 Views)