Why does serial.read stop working?

michinyon:
That seems to be a gratuitously complicated method of implementing a "state machine".

Perhaps your problem is related to using Strings.

The other part of the code that looks dodgy, is where you attempt to read the string from the serial. What do you expect the readStringUntil() function to do, exactly ? Is the other end of your serial communication sending the newline character that you expect ? You might have fallen into some version of the CR vs CR-LF problem.

Thanks for the reply Michinyon, the readstringUntil('\n') works fine in the upper section, so it shouldn't be that. I'm just using that to simulate sending some info through serial by using serial monitor.

What I did find - after another glass of wine and some more debugging - is that the serial is still working, and the while loop isn't being skipped, it just goes by too fast. I added a delay(4000) to the code and was able to get to the next state, but why does it jump like that, when it doesn't in the Hold0 state?

The idea is that the Hold states should just sit there until I enter a command, then go to the next state. This is to give me time to add/remove grains, etc.