淳熙 姜
/
JOYSTICK_control
いろんな出力のお試しコード
Diff: main.cpp
- Revision:
- 3:21210e2561c8
- Parent:
- 2:a8e6713fbe41
diff -r a8e6713fbe41 -r 21210e2561c8 main.cpp --- a/main.cpp Sat May 16 07:21:07 2015 +0000 +++ b/main.cpp Sat May 16 09:08:16 2015 +0000 @@ -3,7 +3,6 @@ //***************************************** #include "mbed.h" -#include "main.h" //デジタル読み取りピンの指定 DigitalInOut Abutton(dp25); @@ -21,8 +20,8 @@ AnalogIn JOYstick_UD(dp10); //PWM出力ピン(モーター?)の指定 -PwmOut motorLR(dp1); -PwmOut motorUD(dp2); +PwmOut motorUDplus(dp1); +PwmOut motorUDminus(dp2); //シリアル入出力ピンの指定 Serial Controller(dp16, dp15); @@ -30,11 +29,11 @@ int main(void){ //初期設定 - myLED = LOW; - motorA = LOW; - motorB = LOW; - motorLR = LOW; - motorUD = LOW; + myLED = 0; + motorA = 0; + motorB = 0; + motorUDplus = 0.5; + motorUDminus = 0.5; //出力レートの指定 Controller.baud(9600); @@ -63,37 +62,37 @@ //ジョイスティックの左右方向読み取り tmp = JOYstick_LR.read(); Controller.printf("%f ",tmp); - motorLR = tmp; //ジョイスティックの上下方向読み取り tmp = JOYstick_UD.read(); Controller.printf("%f\n",tmp); - motorUD = tmp; + motorUDplus = tmp; + motorUDminus = 1-tmp; //タクトスイッチの動作全般 //タクトスイッチ(Aボタン)が押されていれば"A"を表示.モータ正回転 - if(Abutton == HIGH && Bbutton == LOW){ + if(Abutton == 1 && Bbutton == 0){ Controller.printf("A \n"); - motorA = HIGH; - motorB = LOW; + motorA = 1; + motorB = 0; } //タクトスイッチ(Bボタン)が押されていれば"B"を表示.モータ逆回転 - else if(Abutton == LOW && Bbutton == HIGH){ + else if(Abutton == 0 && Bbutton == 1){ Controller.printf("B \n"); - motorA = LOW; - motorB = HIGH; + motorA = 0; + motorB = 1; } //タクトスイッチ(AボタンとBボタン)が押されていれば"AとB"を表示.モータは動かない - else if(Abutton == HIGH && Bbutton == HIGH){ + else if(Abutton == 1 && Bbutton == 1){ Controller.printf("A and B \n"); - motorA = HIGH; - motorB = HIGH; + motorA = 0; + motorB = 0; } //何も押されていなければ、何も表示しない.モータは動かない else{ - motorA = HIGH; - motorB = HIGH; + motorA = 0; + motorB = 0; } }