     WiServer.print ("</div></body></html>");
 }
 
-
-void move_to_start() 
-{
-    myMotor.write(80);
-    //delay(500); // delay 1000ms, this allows the previous instruction to be finished. 
-}
-     
-
-void move_to_end() 
-{
-    myMotor.write(70);
-}
-
-void move_to_ninty()
-{
-    myMotor.write(90);
-}
-
+void arm() 
+{
+    unsigned long now = millis();
+    
+    // don't try rearming if we already tried earlier, this will confusing the APM
+    if(now - lastArmTime < 6000) {
+         return;
+    }
+    
+    Serial.println("arming");
+    throttleMotor.write(servoAngleForSpeed(0));
+    yawMotor.write(servoAngleForSpeed(130));
+    delay(5000);
+    resetMotors();
+    armed = 1;
+    lastArmTime = now;
+}


    if(!state) {
        WiServer.init(sendMyPage);
    }

    // Run WiServer
    WiServer.server_task();

        return true;
    }
     
    if (strcmp (URL, "/?OPERATION=reset") == 0) {
        resetMotors();
        _webpageHelper();
        return (true);
    }
 
    if (strcmp (URL, "/?OPERATION=arm") == 0) {
        arm();
        _webpageHelper();
        return (true);
    }
    
    if (strcmp (URL, "/?OPERATION=throttle25") == 0) {
        throttleMotor.write(servoAngleForSpeed(25));
        _webpageHelper();
        return (true);
    }
    
    if (strcmp (URL, "/?OPERATION=throttle50") == 0) {
        throttleMotor.write(servoAngleForSpeed(50));
        _webpageHelper(); 
        return (true);
    }
    
    if (strcmp (URL, "/?OPERATION=throttle75") == 0) {
        throttleMotor.write(servoAngleForSpeed(75));
        _webpageHelper(); 
        return (true);
    }
    
 
  
    Serial.println("url not found");
    // URL not found
    return false;
}

void resetMotors()
{
    throttleMotor.write(servoAngleForSpeed(0));
    yawMotor.write(servoAngleForSpeed(50));
    rollMotor.write(servoAngleForSpeed(50));
    pitchMotor.write(servoAngleForSpeed(50));    
}

void setup() 
{    
     // Required for I/O from Serial monitor
    Serial.begin(57600);
 
    Serial.println("Starting WiFi");
     // Initialize WiServer and have it use the sendMyPage function to serve pages
    WiServer.init(sendMyPage);


    rollMotor.attach(6);
    yawMotor.attach(7);
    throttleMotor.attach(8);
    pitchMotor.attach(9);
    
    WiServer.enableVerboseMode(true);

    Serial.println("setting all channels at resting state");
    resetMotors();
    delay(5000);
    
    arm();    
    
    /*
    Serial.println("setting throttle to 25");
    throttleMotor.write(servoAngleForSpeed(25));
    */
    
 }

void loop()
{
