01-19-2016 07:11 PM
I'm having trouble switching between the true and false case between case structures. I'm trying to write a VI that generates a random number between 0 and 10 once every 0.5 seconds, and then adds the numbers together until the running sum reaches or exceeds 100. At that point it should start to subtract the randomly generated numbers until it reaches 0, then switch to adding them again etc.
I am having trouble switching to the 'false' case once the sum excedes 100. If anyone can help with this that would be awesome!
Solved! Go to Solution.
01-19-2016 07:19 PM
Move the comparison outside the case structure.
Lynn
01-19-2016 07:41 PM
Use another shift register to hold which way you are going. A simple Boolean should work.
The generation of the random number should be outside of the case structure (since you are doing that regardless). But the add/subtract and the comparison to see if you need to switch states should be inside of the case structure.
You should also just use 0 to initialize your shift register that holds your current total. Makes things a little simpler.
01-19-2016 07:52 PM
Thank you for your input so far. My biggest problem is with the Boolean, as I am inexperienced in that area. Can you please elaborate on how adding another shift register helps?
Thanks.
01-19-2016 10:54 PM
01-19-2016 10:56 PM - edited 01-19-2016 10:58 PM
You see, one shift register holds the data, and the other the direction to count on the next iteration. This structure is a very, very simple state machine.
Mike...
01-20-2016 12:26 AM
I don't quite understand your first statement. You suggest that I put an enumeration with respective values for "Count Up" or "Count Down" respectively inside the case structure? I'm also not quite sure how to test to see if it's greater than 100 or less than 0. I understand that I use a comparison here, but what do I wire it up to?
Thank you for all your help so far.
01-20-2016 01:30 AM
01-20-2016 03:30 AM - edited 01-20-2016 03:30 AM
@Valsae wrote:
I don't quite understand your first statement. You suggest that I put an enumeration with respective values for "Count Up" or "Count Down" respectively inside the case structure?
You use the enum for the selector of the case structure. You can then use the shift register to tell the next iteration what to do.
01-20-2016 07:32 AM