Code to work once out side the loop

Hello
Its been a while since i've played with Arduino
Im making a digger move on my model railway using 4 servos.
what i would like to do is run the code while im testing how far to move the servos..

say i wanted to run this code once out side the loop how do i do it?
for(pos = 80; pos < 100; pos += 1){ // down
up.write(pos);
delay(10);
}

This is my code:

// This is for a model digger in Ho scale for a model railway
// Jason fletcher = 11.01.2014

#include <Servo.h>

Servo diggerturn ;
Servo dig ;
Servo up ;
Servo down ;

int pos = 0;
void setup()

{
diggerturn.attach(8);
up.attach(9);
down.attach(10);
dig.attach(11);
}

void loop()
{ // Open //

for(pos = 140; pos>= 20; pos-= 1){ // Empty the bucket release the tention
dig.write(pos);
delay(10);
}

for(pos = 120; pos>= 80; pos -= 1){ // Release the tention on the the down
down.write(pos);
delay(10);
}

for(pos = 120; pos>= 50; pos-= 1){ //up
up.write(pos);
delay(550);
}

// low number = police man, high number = pit
for(pos = 65; pos < 110; pos += 1) // Turn towards the pit
{
diggerturn.write(pos);
delay(100); // Speed it turns
}

delay(1000);

for(pos = 110; pos>= 65; pos-=1) // Turn away from the pit
{
diggerturn.write(pos);
delay(100); // Speed it turns
}

for(pos = 80; pos < 100; pos += 1){ // down
up.write(pos);
delay(10);
}

} /// END //.............................

Many thanks Jason

You have several loops - what do you mean by "outside"?

Hi, if you want to run it once only, then make it the last thing you do in the setup part of the sketch, it will be executed once and then the arduino will run in the loop part, never to return to setup, unless reset.

Hope that answers your question.

Tom... :slight_smile:

diggerturn.attach(8);
Lucky you. My Arduino doesn't have a smiley face pin.

DO NOT USE THE COPY FOR FORUM OPTION. It is only there to irritate us.

Sorry PaulS

Hello TomGeorge

can you please show me an example

can you please show me an example

The servo "attach"s you have in your code in "setup()" are not executed in "loop()", and are only executed once.
Does that answer your question?

Hint: "setup()" and "loop()" are just ordinary functions - the laws of C/C++ are the same in both.

thank you