Implementing a remote controlled "STOP" via an interrupt?

morecowbell001:
PeterH- thank you for the reply. I'm very intrigued into how to do this. Can you tell me what code I would need to continue to handle incoming messages while it is carrying out the action sequence? Or point me in the direction of any example of this?

Design your sketch so that it does not ever need to stop and wait for time to pass or an event to happen. The 'blink without delay' example sketch shows you how to do this for timed actions. Essentially, instead of your logic being carried out by a chunk of code that does each thing in sequence and stops and waits until it's necessary to do the next thing, you turn the structure inside out so that there is a single piece of code which is executed repeatedly which tests for things it may need to do.

For example, if you need to handle commands from a serial port your code would check whether there were any characters waiting to be read; if there were, it would read and buffer them. If the buffer contains a complete message ready to be processed then it would call the code to process it.

If the code needs to flash an LED it works out whether it is time to turn the LED on or off and if so does it - and if it's not time yet, it does nothing and carries on.

If your code needs to move a servo through a defined path at a specified speed, it tests whether it's time to adjust the servo position yet and if so moves the servo to the next position.

When you structure your code using this non-blocking approach, you can handle events from any source in any order at any time. If you receive a command that tells you to abort some action that was in progress, you just update the state to show that the activity is no longer in progress.