手動機 ヌクレオ用のプログラムです

Dependencies:   mbed

Fork of F3RC_syudou_slave by F3RC1班

main.cpp

Committer:
yuto17320508
Date:
2017-08-25
Revision:
4:5ba58456c3ee
Parent:
3:1a3ed86511d3
Child:
5:72e5a850678a

File content as of revision 4:5ba58456c3ee:

#include "mbed.h"

Serial pc(USBTX,USBRX);
BusIn in(PA_7,PA_6,PA_5,PA_4);
PwmOut moter_1(PB_14);
PwmOut moter_2(PB_15);
DigitalOut cyli_1(PB_5);
DigitalOut cyli_2(PB_3);
DigitalOut cyli_3(PA_10);
//フォトインタラプタ上
InterruptIn photo_1(PC_2);
//フォトインタラプタ下
InterruptIn photo_2(PC_3);

int num;

//モーターの出力の設定
double moter_power = 0.7;


//腕上昇下降の関数
void up()
{
    moter_1=moter_power;
    moter_2=0;
}
void down()
{
    moter_1=0;
    moter_2=moter_power;
}
void stop()
{
    moter_1=0;
    moter_2=0;
}
//フラグ
int up_flag=1;
int down_flag=1;
//フォトトランジスタのフラグ呼び出し
void photo_1_rise()
{
    stop();
    up_flag=0;
}
void photo_1_fall()
{
    up_flag=1;
}
void photo_2_rise()
{
    stop();
    down_flag=0;
}
void photo_2_fall()
{
    down_flag=1;
}
int main()
{


//フォトインタラプタ1
    photo_1.rise(&photo_1_rise);
    photo_1.fall(&photo_1_fall);

//フォトインタラプタ2
    photo_2.rise(&photo_2_rise);
    photo_2.fall(&photo_2_fall);
    while(1) {

        num=in;


//腕1 上昇下降
        if(num == 1 && up_flag==1) {//上昇
            up();
        } else if(num == 2 && down_flag==1) {//下降
            down();
        } else {
            stop();
        }

//腕1 開閉
        if(num == 3) {
            cyli_1=1;
        } else if(num == 4) {
            cyli_1=0;
        }

//腕2 上昇下降
        if(num == 5) {
            cyli_2=1;
        } else if(num == 6) {
            cyli_2=0;
        }

//腕2 開閉
        if(num == 7) {
            cyli_3=1;
        } else if(num == 8) {
            cyli_3=0;
        }
        pc.printf("%d\n\r",num);
    }
}