Okay! the answer came to me after typing my response below, but brings up a new question
What's happening is the While loop goes by too fast, so delay paused it, if I put it inside another while loop, I can make it stick around
#include <SM.h> //Simple State Machine Library
//State Machine names go here MachineName(headstate,bodystate)
SM Hold0(H0h,H0b);
SM Strike(S1);
SM Hold1(H1b);
SM Mash(M1);
//SM Hold2(H2) ;
//SM Boil(B1) ;
/**** global variables *****/
double Setpoint;
//String str;
void setup(){
Serial.begin(9600);
}
void loop(){
EXEC(Hold0);
}
State H0h(){
Serial.println("hello");
}
State H0b(){
while (Serial.available()>0) {
String str = Serial.readStringUntil('\n');
if(str == "next"){
Serial.println("going to Strike");
EXEC(Strike);
Hold0.Finish();
}
}
}
State S1(){
Serial.println("S1");
Setpoint = 155;
int temp = 150; //manual faking of temperature
while (temp < Setpoint){
temp++;
Serial.print(Strike.Statetime());
Serial.print(" setpoint= ");
Serial.print(Setpoint);
Serial.print(" temp= ");
Serial.println(temp);
}
Serial.println("going to Hold1");
EXEC(Hold1);
Strike.Finish();
}
/*State H1h(){
Serial.println("H1");
//Hold1.Set(H1b);
}*/
State H1b(){
while ((Hold1.Statetime() - 5000000)){
while (Serial.available()>0) {
String foo = Serial.readStringUntil('\n');
if(foo == "foo"){
Serial.println("going to Mash");
EXEC(Mash);
Hold1.Finish();
}
else if(foo !="foo"){
Serial.println("HUH?");
}
}
}
Serial.println("h1b");
}
State M1(){
Serial.println("Mash");
}
But now it sticks around so long that if I type "foo" after the Hold1 state should have finished, I still get the output "going to Mash".
So, now I'm not quite understanding what "State.Finish()" really means. Seems like Finish() should make the state stop.
Anyway, michinyon if there is some less complicated way to do this, I'm all ears. I've looked at Switch(case), but that gets more complicated in a hurry when trying to handle timers, sensor inputs, and serial inputs all at once. I was hoping SM would be the more elegant solution, but maybe not ?