Swapping over from a state machine in mbed, to arduino

Hi everyone,

My project was previously done on the platformIO IDE using mbed as the programming language. It made use of a NEXTION touch screen which sends & receives serial data to start the state machine, or to terminate the process.

So the code for mbed would look something like:

//Initialise the NEXTION screen here

Serial Nextion(TXpin, RXpin, 9600);

//Define Serial Interrupt protocol here

void stop_handler();


int main(){
//attach the stop handler to the NEXTION object

Nextion.attach(stop_handler, Serial::RxIrq);
}

while(1){

statemachine();

}

So, now the board will be changed to another board which is not compatible with mbed, but with Arduino, hence I am porting all the functions to be compatible with Arduino.

My question is, is there a function in Arduino that serves the same functionality as mbed's Serial.attach(funtiontodeploy, onTransferorReceive)?

You can add a global variable that tells the state machine state. Then use it when calling the machine execute in loop():

  if (machineActive) statemachine();

Or do a check at the entry of the state machine, before it forks to the current state.