Arduinoのプログラムが見辛いので貼り付けます。 拙いコーディングですがご容赦を。 // UFO Cachter!! // Adafruit Motor shield library // copyright Adafruit Industries LLC, 2009 // this code is public domain, enjoy! #include #include // DC motor on M1 AF_DCMotor motor1(1); AF_DCMotor motor2(2); AF_DCMotor motor3(3); // DC hobby servo Servo servo1; // set pin numbers: const int buttonPin1 = 14; // pushbutton1 is pin A0 const int buttonPin2 = 15; // pushbutton2 is pin A1 // variables will change: int buttonState1 = 0; // variable for reading the pushbutton status int buttonState2 = 0; // variable for reading the pushbutton status void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("UFO Catcher!"); // initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); // turn on servo servo1.attach(10); servo1.write(0); // turn on motor #1-3 motor1.setSpeed(200); motor1.run(RELEASE); motor2.setSpeed(200); motor2.run(RELEASE); motor3.setSpeed(200); motor3.run(RELEASE); } long v_counter=0; long h_counter=0; int counter=0; void loop() { int i = 0; int j = 0; if (counter == 0){ // read the state of the pushbutton value buttonState1 = digitalRead(buttonPin1); // if it is, the buttonState is HIGH if (buttonState1 == HIGH){ Serial.println("Button1 ON!"); motor1.run(FORWARD); h_counter = 0; for(;;) { h_counter ++; buttonState1 = digitalRead(buttonPin1); if (buttonState1 == LOW){ j = 0; // 瞬断の誤検知防止のため15カウント for(i=0;i 14) break; } } motor1.run(RELEASE); Serial.println("Button1 Release!"); Serial.println(h_counter); counter = 1; } } else{ // read the state of the pushbutton value: buttonState2 = digitalRead(buttonPin2); // if it is, the buttonState2 is HIGH: if (buttonState2 == HIGH){ Serial.println("Button2 ON!"); motor2.run(FORWARD); v_counter = 0; for(;;){ v_counter ++; buttonState2 = digitalRead(buttonPin2); if (buttonState2 == LOW){ j = 0; // 瞬断の誤検知防止のため15カウント for(i=0;i 14) break; } motor2.run(RELEASE); Serial.println("Button2 Release!"); Serial.println(v_counter); counter = 0; delay(100); arm_opendowncloseup() ; return_to_base() ; arm_openclose() ; } } } void return_to_base() { Serial.println("Return To Base!"); motor1.run(BACKWARD); delay(h_counter/140); motor1.run(RELEASE); // motor2.run(BACKWARD); delay(v_counter/150); motor2.run(RELEASE); } void arm_opendowncloseup() //アームを広げて下し閉じて上げる { Serial.println("Open Down Close Up!"); servo1.write(70); motor3.run(FORWARD); delay(9000); // run forward for 9 second motor3.run(RELEASE); delay(100); // 'coast' for 1/10 second servo1.write(-70); motor3.run(BACKWARD); // run in reverse delay(12000); // run backward for 12 second motor3.run(RELEASE); delay(100); // 'coast' for 1/10 second } void arm_openclose() //アームを広げて閉じる { Serial.println("Open Close!"); servo1.write(70); delay(3000); servo1.write(-70); digitalWrite(buttonPin1,LOW); digitalWrite(buttonPin2,LOW); Serial.println("Finish!"); }