通信変えたやつです

Dependencies:   mbed

Fork of F3RC_syudou_slave_3 by F3RC1班

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Serial pc(USBTX,USBRX);
00004 BusIn in(PA_7,PA_6,PA_5,PA_4);
00005 PwmOut motor_1(PB_14);
00006 PwmOut motor_2(PB_15);
00007 DigitalOut cyli_1(PB_5);
00008 DigitalOut cyli_2(PB_3);
00009 DigitalOut cyli_3(PA_10);
00010 //フォトインタラプタ上
00011 InterruptIn photo_1(PC_2);
00012 //フォトインタラプタ下
00013 InterruptIn photo_2(PC_3);
00014 
00015 int num;
00016 
00017 //モーターの出力の設定
00018 double motor_power = 0.6;
00019 
00020 
00021 //腕上昇下降の関数
00022 void up()
00023 {
00024     motor_1=0;
00025     motor_2=motor_power;
00026 }
00027 void down()
00028 {
00029     motor_1=motor_power;
00030     motor_2=0;
00031 }
00032 void stop()
00033 {
00034     motor_1=0;
00035     motor_2=0;
00036 }
00037 //フラグ
00038 int up_flag=1;
00039 int down_flag=1;
00040 //フォトトランジスタのフラグ呼び出し
00041 void photo_1_rise()
00042 {
00043     stop();
00044     up_flag=0;
00045 }
00046 void photo_1_fall()
00047 {
00048     up_flag=1;
00049 }
00050 void photo_2_rise()
00051 {
00052     stop();
00053     down_flag=0;
00054 }
00055 void photo_2_fall()
00056 {
00057     down_flag=1;
00058 }
00059 int main()
00060 {
00061 motor_1.period_us(100);
00062 motor_2.period_us(100);
00063 
00064 //フォトインタラプタ1
00065     photo_1.rise(&photo_1_rise);
00066     photo_1.fall(&photo_1_fall);
00067 
00068 //フォトインタラプタ2
00069     photo_2.rise(&photo_2_rise);
00070     photo_2.fall(&photo_2_fall);
00071     while(1) {
00072 
00073         num=in;
00074 
00075 
00076 //腕1 上昇下降
00077         if(num == 1 && up_flag==1) {//フラグ1で上昇
00078             up();
00079             num=1;
00080             pc.printf("up\n");
00081         } else if(num == 2 && down_flag==1) {//フラグ1で下降
00082             down();
00083             num=2;
00084             pc.printf("down\n");
00085         } else {//止まる
00086             stop();
00087         }
00088 
00089 //腕1 開閉
00090         if(num == 3) {//開く
00091             cyli_1=1;
00092         } else if(num == 4) {//閉じる
00093             cyli_1=0;
00094         }
00095 
00096 //腕2 上昇下降
00097         if(num == 5) {//上昇
00098             cyli_2=0;
00099         } else if(num == 6) {//下降
00100             cyli_2=1;
00101         }
00102 
00103 //腕2 開閉
00104         if(num == 7) {//開く
00105             cyli_3=1;
00106         } else if(num == 8) {//閉じる
00107             cyli_3=0;
00108         }
00109         pc.printf("%d\n\r",num);
00110     }
00111 }