Run state machine if condition met

You want as much as possible for the input(s) and the output(s) to be independent. They should run on their own in loop() with process task(s) like the state machine to connect between.

Any task can be a 1-shot (doesn't restart itself) triggered by another.

You can change inputs, outputs and processes with minimal or no recoding of the rest of the sketch.
You can develop tasks in small controlled sketches to move directly to the main project.
You can build a better code toolbox using IPO tasks.