This commit is contained in:
Nebel 2012-08-30 23:08:43 +09:00
parent c37c972d1e
commit f0b0f370cc

View file

@ -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);
}