11-19-2014 11:06 AM
Hello,
I am trying to write a code that plots a random number everytime a button is pressed. The graph should be the random number on the Y-axis and the number of times the button is pressed on the X-axis. I want to plot the last twenty random numbers. I am using a while loop and a case structure. If the button is pressed, the case structure incruments the number of times the button is pressed and generates a random number. I am using shift registers to keep track of the last twenty numbers generated. When the button is not pressed, the shift registers update the values incorrectly. My code is attached to this question.
I know wiring the last value of the shift registers to the case structure will change the array to all of the last value when the button is not pressed. I know what causes the issue but I am not sure how to fix it. I would appreciate it if you have a look at it and give me some tips.
Thanks in advance.
Solved! Go to Solution.
11-19-2014 11:24 AM - edited 11-19-2014 11:24 AM
Your problem is that the loop is continuously running and your values in the shift register are being overwritten when you are doing nothing.
There are a few ways around this. The simplest would be to use an Event Structure. Another option is to just store your array in the shiftregister. Use Rotate 1D Array and Replace Array Subset to update your array. This is a little more robust and easier to use than using the history option of the shift register.
But the absolute simplest, based purely on what you have told us, is to just use a chart instead of a graph. A chart keeps a history. The default history length is 1024 samples, so you will want to reduce that to 20. Then you just wire your random number straight into the chart and everything is done for you.
11-19-2014 11:30 AM - edited 11-19-2014 11:32 AM
02-12-2015 08:53 PM
the same problems
IA 24 * 19 array populated by an array of fixed positions calculated CASE judge after then as a display case from the outside but I'm looking to fill up to 24 x 19 array of value there is only one value changes how design can make all the specified array value of the position of all the changes it
02-13-2015 07:17 AM
Store your array in a shift register and use Replace Array Subset to update specific elements in your array.