08-05-2013 08:23 AM - edited 08-05-2013 08:24 AM
Hi everybody,
I have a question about clearing the array history. It seems simple but I am really confused...
As the example attached below, I built an array inside a while loop and a for loop. After totally finishing running the program once, when I run it a second time, it seems that the array has memory of the last time, i.e. the array size does not start from 0, and the old number from last time appears, even through it is initialized out of the for loop.
How could I make it start from empty everytime when I restart the array?
Need your help. Thanks a lot. : )
Solved! Go to Solution.
08-05-2013 08:31 AM
08-05-2013 08:38 AM
More specifically, you are initializing the indicator, but the data is actually retained in the shift register. Once you initialize the shift register, the display will show the new data, so there is no need to reninit the indicator.
What is the purpose of the outer FOR loop? It does not seem to add any functionality to the program. If you would remove it, nothing would change.
08-05-2013 08:54 AM
Well, this is not a formal program. I just scrabed a part from my initial program, since it is clear to explain my question...
08-05-2013 08:59 AM
Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?
08-05-2013 09:03 AM - edited 08-05-2013 09:04 AM
@cun wrote:
Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?
I can't see the code, but I imagine auto-indexing is on the while loop tunnel. Disable the auto-indexing on the while loop tunnel and it should go where you need it to go. 🙂
08-05-2013 10:21 AM
@cun wrote:
Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?
Of course the constant goes outside the loop. It should be wired to the left shift register from outside the loop to initialize it. This will initialize when the loop starts.
There is nothing to initialize when the program finishes. Why do you think you need that?
"it doesn't work well" is not a useful description. What happens? What do you expect to happen? On a scale from 1-10, how "well" does it work?
08-05-2013 10:33 AM
I did this and initialized the array out of the for loop, but it also initialized the array for the while loop.: (
What I expect is to initialize the array after finishing the for loop but keeping all the data for every while loop. i.e. When I click the stop button once, the array grows continuously, but when I click it the second time to finish the for loop and stop the whole program, the array will be cleared and start again for the next time run. Thanks.
08-05-2013 10:45 AM
I found that if I don't initialize after finishing the whole program, the array will begin from the last time's result... That is what confused me...
08-05-2013 10:48 AM - edited 08-05-2013 11:08 AM
You should also have a shift regsiter in the FOR loop. This will keep the data for the duration of the program, but clear it at the beginning of the next run.