01-01-2018 12:19 AM
Hello,
I'm trying to create a variable and initialize it to 0. Then, the variable is fetched to an event structure that has three cases: button 1, button 2, and button 3. If button 1 is pushed the variable changes to 1, and if button 2 is pushed, its value becomes 2, and so on. All of this will be in a while-loop and the program stops when the stop button is pushed. Only one button can be pushed at a time (radio button).
Attempt:
I create a 1D array with element's value 0 using the Initialize Array function. Then, I add in the Index Array function to read the value. This is where I'm stuck. Following NI examples, the next step would be adding the Replace Array Subset to replace the element but to a new array. Is it possible to link the updated array back to the original array? ***I feel like this is the worst way to approach the problem but I don't know LabView's functionality well enough to approach it differently.
Please help!
Thanks and Happy New Year 😄
Solved! Go to Solution.
01-01-2018 02:58 AM - edited 01-01-2018 03:32 AM
What is a "variable"? Are you talking about an indicator or wire value to be used by a function?
You don't need an array, all you need is a scalar. Show us what you tried so far.
Are you using a radio button control?
01-01-2018 05:44 AM
It definitely sounds like you are overcomplicating this. Just store the value in a shift register and update it when the buttons are pressed.
01-01-2018 10:45 AM
Hi altenbach,
Basically, I'm looking to initialize a number x = 0. Then, x is wired to an event structure. When an event occurs, the value of x: 1) will be used to do stuff, and 2) will be changed. After the event execution is complete, the new value of x will be fetched to the beginning of the program so the event structure can used this new value for the event cases.
I've attached a snip of what I'm trying to achieve in broken C++ language. My only attempt so far is the array approach but I haven't been able to feed the new value back to the event structure. I'm going to try to use local variable next; though everyone seems to frown upon it.
I hope my attempt in clarifying doesn't confuse you more.
Thanks, Knight 😉
01-01-2018 11:19 AM
Hi crossrulz,
I've looked at tutorials on shift register and it seems that shift register only work in loops? I suppose I could add a loop around the event structure but is there a way around this?
Thanks Knight!
01-01-2018 11:42 AM
SegFault1119 wrote:I've looked at tutorials on shift register and it seems that shift register only work in loops? I suppose I could add a loop around the event structure
Why wouldn't you have a loop around the event structure? It is there in the C++ code.
01-01-2018 12:01 PM
You are right! I was confused with how event structures behave inside a while loop. I will try this out and I might come back with more questions.
Thanks!
01-01-2018 12:03 PM
@SegFault1119 wrote:
I've attached a snip of what I'm trying to achieve in broken C++ language. My only attempt so far is the array approach but I haven't been able to feed the new value back to the event structure. I'm going to try to use local variable next; though everyone seems to frown upon it.
I would simply use a radio-button control. This one flashes a certain LED based on the radio button. (see attached).
(To do "something" for each possible state, wire it to a case structure and create a case for each value. The cases will be named automatically after the button labels. If the case should execute regularly, put in in the timeout case and the radio value in a shift register. Not shown).
I have no idea why you would want to use a local variable next. That makes no sense.
01-01-2018 01:49 PM
Thank you for your VI example. I've played around with it and it's exactly what I'm trying to achieve. Though, I still need to spend more time to understand it.
Also, could you take a quick look at my attachment? I'm trying to work with shift register. The shift register function in my program works but the stop button for the loop doesn't work. The stop button registers when it's being pressed but the loop doesn't stop executing.
01-01-2018 01:57 PM
It was the time out case. I added 200 as you did in your example VI and it's working now.
Thank you very much!