/****************************************** * * This is a test combining the StateMachine * and neotimer in dynamically generated states * and timer objects. * * Because these are dynamically generated * the compiler can't really determine the * correct memory usage and the microcontroller * will crash after a given quantity of states. * * Currently more than 25 states crashes the micro * ******************************************/ #include #include #define STATES 25 StateMachine machine = StateMachine(); State* states[STATES]; Neotimer timers[STATES]; void setup() { Serial.begin(9600); randomSeed(analogRead(0)); for(int i=0; iaddTransition(&stateTransition, (i==(STATES-1)) ? 0 : i+1); /* LAMBDA TRANSITION states[i]->addTransition([](){ return (timers[machine.currentState].done())?true:false; },(i==(STATES-1)) ? 0 : i+1); */ } } void loop(){ machine.run(); } /****************************************** * Functions to be used as State logic * and transitions logic * if not using lambda functions. ******************************************/ void stateLogic(){ if(machine.executeOnce){ Serial.print("State "); Serial.print(machine.currentState); Serial.println(" Execute Once"); timers[machine.currentState].stop(); timers[machine.currentState].start(); } } bool stateTransition(){ return (timers[machine.currentState].done())?true:false; }