From f0b0f370cc09041d9c9d83d3fb705a5ed7cef0a8 Mon Sep 17 00:00:00 2001 From: kou029w Date: Thu, 30 Aug 2012 23:08:43 +0900 Subject: [PATCH] update --- arduino/catchrobo2012/catchrobo2012.ino | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arduino/catchrobo2012/catchrobo2012.ino b/arduino/catchrobo2012/catchrobo2012.ino index 5450960..3caf987 100644 --- a/arduino/catchrobo2012/catchrobo2012.ino +++ b/arduino/catchrobo2012/catchrobo2012.ino @@ -11,7 +11,7 @@ #define PIN_MOTOR_VERTICAL_2 7 #define PIN_SERVO_BASE 9 -#define PIN_SERVO_CATCHER 10 +#define PIN_SERVO_CATCHER 10 #define PIN_PWR A3 #define PIN_GND A2 @@ -32,7 +32,7 @@ void setup(){ wiiNun.begin(); base.attach(PIN_SERVO_BASE); catcher.attach(PIN_SERVO_CATCHER); - pinMode(PIN_LED , OUTPUT); + pinMode(PIN_LED, OUTPUT); horMotor.attach(PIN_MOTOR_HORIZON_1, PIN_MOTOR_HORIZON_2); verMotor.attach(PIN_MOTOR_VERTICAL_1, PIN_MOTOR_VERTICAL_2); } @@ -60,8 +60,7 @@ void loop(){ // char ax = (char)(accx-0x7F); char ay = (char)(accy-0x7F); // 水平状態を0にする - byte baseDeg = 90; - byte catcherDeg = 90; + static byte baseDeg = 90; if(zbut){ // zボタン押しながら digitalWrite(PIN_LED, HIGH); if(y>0x1F) baseDeg = 180 - atan2(y, x)*180/PI; // 台座をスティックの角度にする @@ -69,22 +68,23 @@ void loop(){ else if(baseDeg > 170) baseDeg = 170; }else{ // zボタン離しながら digitalWrite(PIN_LED, LOW); - horMotor.speed(y); + horMotor.speed(y*2); baseDeg += x/32; // 台座をxに応じて相対移動 } + base.write(baseDeg); if(0); else if(ay > +0x20) verMotor.mode(GO); else if(ay > +0x10) verMotor.speed(+0xCC); - else if(ay < -0x10) verMotor.speed(-0xCC); else if(ay < -0x20) verMotor.mode(BACK); + else if(ay < -0x10) verMotor.speed(-0xCC); + else verMotor.mode(STOP); - catcherDeg = 90; + byte catcherDeg = 100; if(cbut){ // cボタン押すとキャッチャーを離す - catcherDeg = 15; + catcherDeg = 30; } - - base.write(baseDeg); catcher.write(catcherDeg); - delay(10); -} + + delay(50); +}