淳熙 姜 / Mbed 2 deprecated JOYSTICK_control

Dependencies:   mbed

main.cpp

Committer:
Kansuni
Date:
2015-05-16
Revision:
1:b4d995953362
Parent:
0:2ea8da556ef4
Child:
2:a8e6713fbe41

File content as of revision 1:b4d995953362:

//*****************************************
// コントローラのサンプルプログラム
//*****************************************

#include "mbed.h"
#include "main.h"

//デジタル読み取りピンの指定
DigitalInOut Abutton(dp25);
DigitalInOut Bbutton(dp26);

//デジタル出力ピン(モーター)の指定
DigitalInOut motorA(dp4);
DigitalInOut motorB(dp6);

//デジタル出力ピン(LED)の指定
DigitalInOut myLED(LED1);

//アナログ読み取りピンの指定
AnalogIn JOYstick_LR(dp9);
AnalogIn JOYstick_UD(dp10);

//PWM出力ピン(モーター?)の指定
PwmOut motorLR(dp1);
PwmOut motorUD(dp2);

//シリアル入出力ピンの指定
Serial Controller(dp16, dp15);

int main(void){
    
    //初期設定
    myLED = LOW;
    motorA = LOW;
    motorB = 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 = HIGH;
            motorB = LOW;
        }   
        //タクトスイッチ(Bボタン)が押されていれば"B"を表示.モータ逆回転
        else if(Abutton == LOW && Bbutton == HIGH){
            Controller.printf("B \n");
            motorA = LOW;
            motorB = HIGH;
        }
        //タクトスイッチ(AボタンとBボタン)が押されていれば"AとB"を表示.モータは動かない
        else if(Abutton == HIGH && Bbutton == HIGH){
            Controller.printf("A and B \n");
            motorA = HIGH;
            motorB = HIGH;
        }
        //何も押されていなければ、何も表示しない.モータは動かない
        else{
            motorA = HIGH;
            motorB = HIGH;
        }
        
        //100ms待機
        wait(0.1);
        
    }
    
}