       servo3.write(130);
       legPos1 += 1;
       servo2.write(legPos1);
-      delay(15);                       // waits 15ms for the servo to reach the position
-      
+      delay(15);                       // waits 15ms for the servo to reach the position 
   }
   
+}
+
+void bow(Servo servo1){
+  for (pos = 0; pos <= 65; pos += 1) { // goes from 0 degrees to 180 degrees
+    // in steps of 1 degree
+    servo1.write(pos);              // tell servo to go to position in variable 'pos'
+    delay(15);                       // waits 15ms for the servo to reach the position
+  }
+  for (pos = 65; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
+    servo1.write(pos);              // tell servo to go to position in variable 'pos'
+    delay(15);                       // waits 15ms for the servo to reach the position
+  }
 }
 
 void rest(Servo servo1, Servo servo2, Servo servo3) {

      servo1.write(pos);
      servo2.write(pos-90); 
      servo3.write(140);
//      servo2.write(legPos);
      legPos -= 1;

      delay(15);
      servo2.write(legPos);


      
  }
    for (pos = 145; pos >= 125; pos -= 1) { // goes from 180 degrees to 0 degrees
      servo1.write(pos);              // tell servo to go to position in variable 'pos'

      if (commands[i] == "sword"){
        startTime = millis();
        Serial.print("wagao");
        while (millis() < startTime + durations[i].toInt()*1000) {
          swordFight(arm1,arm2,legs);      
        }
      commands[i] = "";
       } else if (commands[i] == "walk") {
          startTime = millis();
          Serial.print("wagao");
          while (millis() < startTime + durations[i].toInt()*1000) {
           walk(arm1,arm2,legs);      
          }
          commands[i] = "";
      } else if (commands[i] == "bow") {
          startTime = millis();
          Serial.print("wagao");
          while (millis() < startTime + durations[i].toInt()*1000) {
           bow(head);
           head.write(65);    //return to upright position      
          }
          commands[i] = "";      
      }
    }

