Go Down

Topic: Implementing a remote controlled "STOP" via an interrupt? (Read 584 times) previous topic - next topic

morecowbell001

Thanks guys- I have tried the encoder/decoder chips, but I wanted to eliminate them and just use VirtualWire and an Arduino on both ends, which works to send the messages... just not sure how to react to those messages.

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?

Thanks again!


PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

morecowbell001

Ah!  I get it now. Thanks guys for that example!

Ok... that means that I have a lot of reconfiguring of the code to do, but I get it.  I looked over the blinking without delay example and understand the concept. I'll have to look for an example of a similar non-blocking code that has some more inputs and outputs so I can better understand how to translate my code into that.  I'll dig around.  If anyone has any good examples of this type of thing, please let me know.

Go Up