淳熙 姜
/
JOYSTICK_control
いろんな出力のお試しコード
Diff: main.cpp
- Revision:
- 0:2ea8da556ef4
- Child:
- 1:b4d995953362
diff -r 000000000000 -r 2ea8da556ef4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 14 08:34:54 2015 +0000 @@ -0,0 +1,105 @@ +//***************************************** +// コントローラのサンプルプログラム +//***************************************** + +#include "mbed.h" +#include "main.h" + +//デジタル読み取りピンの指定 +DigitalInOut Abutton(dp25); +DigitalInOut Bbutton(dp26); + +//デジタル出力ピン(モーター)の指定 +//今回のみオープンドレインを用いて行う +DigitalInOut motorA(dp5); +DigitalInOut motorB(dp27); + +//デジタル出力ピン(LED)の指定 +DigitalInOut myLED(LED1); + +//アナログ読み取りピンの指定 +AnalogIn JOYstick_LR(dp4); +AnalogIn JOYstick_UD(dp13); + +//PWM出力ピン(モーター?)の指定 +PwmOut motorLR(dp1); +PwmOut motorUD(dp2); + +//シリアル入出力ピンの指定 +Serial Controller(dp16, dp15); + +int main(void){ + + //初期設定 + myLED = LOW; + motorA = OD_LOW; + motorB = OD_LOW; + motorLR = LOW; + motorUD = LOW; + + //出力レートの指定 + Controller.baud(9600); + + //デジタル入出力ピンの動作設定 + Abutton.input(); + Bbutton.input(); + motorA.output(); + motorB.output(); + + int l=0; + while(1){ + wait(0.5); + if(Controller.readable()){ + break; + } + l ^= 1; + myLED = l; + } + + float tmp; + while(1){ + + //ジョイスティックの左右方向読み取り + tmp = JOYstick_LR.read(); + Controller.printf("JOYSTICK LR:%f",1-tmp); + Controller.printf("\n"); + motorLR = tmp; + + //ジョイスティックの上下方向読み取り + tmp = JOYstick_UD.read(); + Controller.printf("JOYSTICK UD:%f",1-tmp); + Controller.printf("\n"); + motorUD = tmp; + + //タクトスイッチの動作全般 + + //タクトスイッチ(Aボタン)が押されていれば"A"を表示.モータ正回転 + if(Abutton == HIGH && Bbutton == LOW){ + Controller.printf("A \n"); + motorA = OD_HIGH; + motorB = OD_LOW; + } + //タクトスイッチ(Bボタン)が押されていれば"B"を表示.モータ逆回転 + else if(Abutton == LOW && Bbutton == HIGH){ + Controller.printf("B \n"); + motorA = OD_LOW; + motorB = OD_HIGH; + } + //タクトスイッチ(AボタンとBボタン)が押されていれば"AとB"を表示.モータは動かない + else if(Abutton == HIGH && Bbutton == HIGH){ + Controller.printf("A and B \n"); + motorA = OD_HIGH; + motorB = OD_HIGH; + } + //何も押されていなければ、何も表示しない.モータは動かない + else{ + motorA = OD_HIGH; + motorB = OD_HIGH; + } + + //100ms待機 + wait(0.1); + + } + +} \ No newline at end of file