01-24-2011 10:31 AM
Hi,
I'm trying to display some elements of an array, suppose elements 0 to 9, with a specified delay between display of any two element, and I don't want this delay affect the rest of my code. Can you please guide me how to do this?
I appreciate your help.
01-24-2011 10:59 AM
Does the entire array already exist, and then you want to display it one element at a time?
If so, pass the array into a For loop that iterates 10 times.
The array will autoindex, then you can pass that element to an indicator.
By placing a wait in the loop, you can control how long each element is shown in the indicator.
01-24-2011 11:17 AM
Thanks Cory for your reply.
Yes, the entire array already exists. There are two problems that I cannot solve.
First, the displayed element controls another part of my code. In case that I use a loop I have to take the displayed element out of the loop, which is not possible until the loop is finished. (also note that I cannot copy the rest of the code into the loop)
Second, the delay affects the rest of my code. I want to wait a few seconds before displaying next element while the other parts of the code are running normally.
01-24-2011 01:06 PM
@hknima wrote:
First, the displayed element controls another part of my code. In case that I use a loop I have to take the displayed element out of the loop, which is not possible until the loop is finished. (also note that I cannot copy the rest of the code into the loop)
Does the array ever change once it is created? If not, you can create a local variable of your array in a For loop that is completely seperate from the rest of your code. Just make sure you pay attention to your data flow to ensure that the local variable is referring to the array at the correct point in time.
Second, the delay affects the rest of my code. I want to wait a few seconds before displaying next element while the other parts of the code are running normally.
This is why the For loop should be seperate from the rest of the code. If the two loops run in parallel, a delay in one will not affect the timing of the other.
01-24-2011 02:57 PM
Thanks Cory for your response, it really helped me to improve the code. However the main problem is still unsolved.
I created the local variable in the For loop, but still I cannot obtain the array values outside the loop and have to wait until the loop is finished.
The process that I'm trying to reach is that at iteration 1 I get the first element of the array (outside the loop). After a few seconds (the delay time) at iteration 2 I get the second element of the array (again outside the loop), and so on.
The problem that I'm still struggling is that I cannot get the elements of array (one by one) outside the loop until the loop is finished.
Again thanks for helping me resolving this issue.
01-24-2011 02:59 PM
What exactly is happening to your array in your main loop?
Do you have some initialized array that is being indexed one element at a time in your main loop?
Or is the array actually being created one element at a time?
If you have to wait for your main loop to finish in order for the array to be complete, than you can't really get the array before that.
Would you mind posting your code so we could get a better idea of what is going on?
01-24-2011 04:23 PM
The code is fairly large so I just attached the problematic part.
When the toggle switch passes a true value, the slider is changed manually and the output is picked accordingly. However when the toggle passes a false value I expect that the slider starts automatically from 1 and increases by 1 every 2 seconds, and also expect that the corresponding value (from array X) is shown on the front panel.
As you can see the For loop is not useful here since it returns only the last value to the slider.
Note that X is obtained from another part of the code, and "element" is going to be used in other parts of the code.