how to do a one time task in arduino ????

i have copied this 2-Way motor control program to try running a dc motor... it ran, but it the loop is happens endlessly ,,
what can i do to have the whole process under the loop function to happen for only one time???[/b][/b]

the program goes like this:

int motorPin1 = 5; // One motor wire connected to digital pin 5
int motorPin2 = 6; // One motor wire connected to digital pin 6

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pins as an output:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);

}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
rotateLeft(150, 500);
rotateRight(50, 1000);
rotateRight(150, 1000);
rotateRight(200, 1000);
rotateLeft(255, 500);
rotateRight(10, 1500);
}

void rotateLeft(int speedOfRotate, int length){
analogWrite(motorPin1, speedOfRotate); //rotates motor
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
delay(length); //waits
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
}

void rotateRight(int speedOfRotate, int length){
analogWrite(motorPin2, speedOfRotate); //rotates motor
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
delay(length); //waits
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
}

void rotateLeftFull(int length){
digitalWrite(motorPin1, HIGH); //rotates motor
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
delay(length); //waits
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
}

void rotateRightFull(int length){
digitalWrite(motorPin2, HIGH); //rotates motor
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
delay(length); //waits
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
}

it ran, but it the loop is happens endlessly ,,
what can i do to have the whole process under the loop function to happen for only one time???

If you want something to happen once, the usual advice is to do it in setup(), instead. It seems stupid to try to force loop() to do something once.

Of course, that is possible.

bool doneIt = false;

void loop()
{
   if(!doneIt)
   {
       doIt();
       doneIt = true;
   }
}

tnk u sir ! is this the exact code i needed and i'll just paste it on my sketch ? tnks!

Doing a break inside loop(); isn't the best way to do a one-time task. Paste the content of the loop() function inside setup(), after all declarations you have, then delete the content of loop();

PS: edit the subject of your topic to something more problem-related like "how to do a one time task" or something

Cheers

You have a DC motor wired directly to the digital pins?
No other supporting hardware? Shield? Transistors?

What type of motor?

Is everything working as you expected? Whats the end goal of your project?