stopping a sketch once completed

Hi folks, hoping someone can help me. Im writing a sketch and having some trouble with something no doubt is insanely easy, but I cant find anything about it on-line. I want it to follow a set program then stop, but instead once its completed said task it continues to repeat it.

My program is:

/* motor driver control. */

int motor1APin = 6; // H-bridge leg 1 int motor2APin = 7; // H-bridge leg 2

void setup() { pinMode(motor1APin, OUTPUT); pinMode(motor2APin, OUTPUT); }

void loop() { digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge low digitalWrite(motor2APin, HIGH); // set leg 2 of the H-bridge high delay (5000); digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge low digitalWrite(motor2APin, LOW); // set leg 2 of the H-bridge low delay (1000); digitalWrite(motor1APin, HIGH); // set leg 1 of the H-bridge low digitalWrite(motor2APin, LOW); // set leg 2 of the H-bridge high delay (5000); digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge low digitalWrite(motor2APin, LOW); // set leg 2 of the H-bridge low }

this is basically a circuit set up with a H Bridge IC Chip for changing the direction of a motor, but i need it to completely stop after this set of tasks. When using PBasic you can just write "end" at the end which would stop it- is there an alternative for this? Ive just realised its in a void loop() - could that be it?

Any help is greatly appreciated!!

Ive just realised its in a void loop() - could that be it?

Nail struck squarely on head.

Put run-once code in "setup()".

please use code tags when posting code.

It is better to think of stopping the sketch doing whatever it was doing rather than stopping the sketch.

In this case if you only want to run through a set of instructions once the easiest thing is to move all the code into setup() and leave loop() empty.

If you do want to stop something from repeating after, say 5 iterations, you need a counter and some code like this, perhaps

if (counter > 5) {
   while(true);
}

That WHILE will loop for ever and the only way to stop it is to press the reset button.

...R

AWOL:

Ive just realised its in a void loop() - could that be it?

Nail struck squarely on head.

Put run-once code in "setup()".

please use code tags when posting code.

Ah sorry didnt realise till now there was a code tag :)

There are a few different methods for stopping a sketch explained here: http://arduino.land/FAQ/content/7/47/en/how-to-stop-an-arduino-sketch.html

thanks everybody - got it XD