Running Firmata parallel to other functions

Just write serial code to implement a State Machine. Construct your own commands to handle all needed functions. As an example (crude) of how such a code may function, envision a serial calculator with verbs" Add, Sub, Div, Mul..."

https://forum.arduino.cc/t/dont-cross-the-streams-fp-scientific-calculator-serial-co-processor/144054