I am developing a simple state machine. I have a 'wait for event' state, where it waits until I press a boolean button before it goes to the next state. The button is "switch when pressed." When it is pressed, it remains pressed down until it is released. While it is down, the state machine does to the 'reading' state and collects two arrays of data. Once the button is released, the state machine goes to the 'calculation' state, and arrays of data are displayed on two graphs and calculations are made. Immediately after, the state machine goes back to 'wait for event.' The problem is that since the event structure executes based on the button's 'value change,' when I release the button the event structure executes again, and all my data indicators and graphs are reset to default. I need them to all reset, but only when the button is pressed down, not when it is released. Does anyone know how to fix this?
You have several serious architectural problems. First of all, the event locks the panel until the event completes, but since the code is in the inner while loop elsewhere at that time, it cannot react to the user and the loop can never complete. Catch 22!
You need to rearchitect in a more reasonable way. Think State Machine!
Maybe get rid of the inner loop and use the outer while loop (and timeout event to do the looping). Maybe place the event structure in a parallel loop to do the UI.
Maybe all you need is get rid of the useless event structure and use a case structure and a reasonable polling wait. (The FALSE case has the inputs wired through)
Note that is is typically a bad idea to autoindex on a while loop output tunnels, because if it runs forever, you'll eventually run out of memory. Not bulletproof!