[quote author=Asa Herring link=topic=206419.msg1519117#msg1519117 date=1387902004]
I didn’t think that you would want to sift through my mess. I was hoping that there was a function that would just kill the stack.
As bad as it is, this code works mostly as I want it to. It needs a little polishing since I have move on, in some places before completely finishing up each area.
OK, without wading through all the function calls, I'll speak on general principles, and I speak to the way I would do it. There are other ways, such as unwinding the stack, but this is what I'd do. Hmm... perhaps this way is what those other posters meant by unwinding the stack.
return is your friend, as is a bool to indicate you want to stop.
If you end up in allStop(), you check for a keypress to indicate a wish to stop. At that point, you should set a boolean variable to indicate that you want to return to loop(), and start over. Then, you should return. This will get you back to the statement after the call to allStop(). Here's a revised check in allStop()...
in = key;
if (in == '#')
keyTime = 0;
startover = true; // declared globally as bool startover = true;
Note that a break; would suffice here, as the function ends immediately after the while loop.
Now, immediately after each call to allStop(), you place a bit of code...
if (startover) return;
Each return gets you one function closer to loop. When the returns take you back to a statement in loop(), tyou will continue to process loop(). At this point, you need to use if (startover) or if ( ! startover) to control your program flow such that you only execute the code at the beginning of loop().
To cite an example: Suppose you are in moveToNextStation(), and the user presses the '' key, sending you to allStop(). The use then presses '#', and you set startover and return to the **if(startover) return;* line in moveToNextStation().
So you return. assume you had called moveToNextStation() from showBack(). Your modified code in showBack() would read
if (startup) return;
inputDigitCount = 0;
so you would return, perhaps to keyPadFunction(). Basically, at every call to a function, that COULD lead to allStop(), you check for startover. In the first part of loop(), you would set startover to false.
While I think of it, you can eliminate the doAnAllStop() function, and replace the calls to it with allStop();
As I say, there may be other was, and they might be easier.