Finite state machine - SergeGit/rc-tank-platform GitHub Wiki
Links
Arduino state machines
https://arduino.stackexchange.com/questions/63488/wanted-to-control-2-servos-with-serial-read/63491#63491
https://www.teachmemicro.com/arduino-state-machine-tutorial/
https://arduinoplusplus.wordpress.com/2019/07/06/finite-state-machine-programming-basics-part-1/
Example Arduino
As example of the general structure:
int state = 0;
void loop(){
switch(state){
case 0:
if(Serial.available()>0){
int input = Serial.read();
//take appropriate action
state = 1; //do state transistion
}
break;
case 1:
if(Serial.available()>0){
int input = Serial.read();
//take appropriate action
state = 0; //do state transition
}
break;
}
}