user53516: #include <AFMotor.h> 

AF_DCMotor motor(2,MOTOR12_64KHZ); 

void movefor ();

void moveback();


    void setup() 

    {



    Serial.begin(9600); 

    Serial.println("Motor test!");` `motor.setSpeed(200); 

    movefor ();
    moveback ();
    }

        void movefor( ){
        motor.run(FORWARD); 
    delay(1000); 
    motor.run(RELEASE); 
     delay(100);
    }

    void moveback( ) {
      motor.run(BACKWARD);
    delay(1000);  
    motor.run(RELEASE); 
     delay(100);
    }

While trying to compile this the error message is error compiling for board Arduino Uno
I want the functions outside loop so removed it.
Even if I keep void loop and leave it blank then my motors will like run forward, backward and forward afterwards continuously . 

user2967: You can't, and shouldn't, remove the loop function. Arduino sketches must have a setup function and a loop function. The setup function is called once and the loop function is called repeatedly.
Just make your loop function look like this:
void loop() {
    movefor ();
    moveback ();
}

Your motor will move forward, then move backwards, forever.
Note that you should read up on how to avoid using the delay function. You really need to use millis() to do your timing rather than delays. Do an internet search on "Arduino blink no delay." That's basic Arduino programming.

53516: <pre><code>#include &lt;AFMotor.h&gt; 

AF_DCMotor motor(2,MOTOR12_64KHZ); 

void movefor ();

void moveback();


    void setup() 

    {



    Serial.begin(9600); 

    Serial.println("Motor test!");` `motor.setSpeed(200); 

    movefor ();
    moveback ();
    }

        void movefor( ){
        motor.run(FORWARD); 
    delay(1000); 
    motor.run(RELEASE); 
     delay(100);
    }

    void moveback( ) {
      motor.run(BACKWARD);
    delay(1000);  
    motor.run(RELEASE); 
     delay(100);
    }
</code></pre>

<p>While trying to compile this the error message is <em>error compiling for board Arduino Uno</em></p>

<p>I want the functions outside loop so removed it.</p>

<p>Even if I keep void loop and leave it blank then my motors will like run forward, backward and forward afterwards continuously . </p>
 2967: <p>You can't, and shouldn't, remove the loop function. Arduino sketches must have a setup function and a loop function. The setup function is called once and the loop function is called repeatedly.</p>

<p>Just make your loop function look like this:</p>

<pre><code>void loop() {
    movefor ();
    moveback ();
}
</code></pre>

<p>Your motor will move forward, then move backwards, forever.</p>

<p>Note that you should read up on how to avoid using the delay function. You really need to use <code>millis()</code> to do your timing rather than delays. Do an internet search on "Arduino blink no delay." That's basic Arduino programming.</p>
