Stopping a Program

This is a bit ridiculous, but I am returning to programming after a 45 year haitus. Once a program is uploaded to Sparki and it executes, how does one stop the program from repeating other than unplugging the USB? Thanks, Neil

With these Arduino boards, there is not an easy way to stop an executing program. The main loop just repeats forever until another program is loaded or reset is pushed which will restart the currently loaded program. You could hook up a switch to one of the digital I/O pins and monitor it to see when the user wanted to stop and then just go into a infinite do-nothing loop.
I was thinking of putting in some code to look for a certain pattern of readings from the
ultrasonic sensor to do a similar thing. It could enter the loop whenever it recognized the pattern (say of two short readings of under 5 cm within 2 seconds with a longer reading in between) and you could signal the stop with your hand. You could have it look for another pattern to come out of the loop and you could signal it to continue. With a little fine tuning, you could probably get a fairly reliable system.

Jerry

The main body a program consist of two sections:

[quote] void setup()
{
}
void loop()
{
} [/quote]

Lines of codes in the setup() section will be executed once and then the program stops if there is nothing coded in the loop() section. A finite loop can be written in the setup() section using a FOR or WHILE statements. But once the conditions of the FOR or WHILE have been satisfied, the program stops on the last statement in the setup() section. If the RESET button is pressed or if power is re-cyled back on, the code in the setup() section restarts.

The codes in the loop() section wil be executed and repeated indefinitely until power is turned off. If the power switch in Sparki is ON, the program continues to run even when the USB cable is disconnected. With the power switch off, if the USB cable is connected with the computer on, the electronics components (status LED, LCD, RGB LED, range finder, magnetometer, etc) in Sparki are active. The mechanical components (wheels, servo, gripper) will not be powered. Therefore, with the USB connected and any code using the electronic components will be executed.

One way to have a conditional “stop” in the sketch is to program one of the button in the remote to temporarily suspend execution as in the “Restore_Default” program.