This program is about limit switches

Dependencies:   mbed

main.cpp

Committer:
shina
Date:
2019-09-05
Revision:
2:f64f79a6b5e0
Parent:
1:08c96d55206d
Child:
3:7bbcd64e7127

File content as of revision 2:f64f79a6b5e0:

/////////////////////////////////////
/*NHK2019*/
/*Aチーム手動機リミットスイッチ用プログラム*/
////////////////////////////////////

#include "mbed.h"
Serial master(PC_6,PC_7);
Serial pc(USBTX,USBRX);
DigitalIn limit0(D10);//右上ラック
DigitalIn limit1(D9);//左上ラック
DigitalIn limit2(D8);//右下ラック
DigitalIn limit3(D7);//左下ラック

DigitalIn limit4(D6);//回収機構右
DigitalIn limit5(D5);//回収機構左
DigitalIn limit6(D4);//吐き出し1
DigitalIn limit7(D2);//吐き出し2
DigitalOut green(D12);//電源確認
DigitalOut red(D11);//動作確認


//データ格納用変数
char data;



//関数プロトタイプ宣言
void send_data(char send);

//main()関数
int main(){
    
    
    limit0.mode(PullUp);
    
    limit1.mode(PullUp);
    
    limit2.mode(PullUp);
    
    limit3.mode(PullUp);
    
    limit4.mode(PullUp);
    
    limit5.mode(PullUp);
    
    limit6.mode(PullUp);
    
    limit7.mode(PullUp);
    
    while(true){
        
        if(!limit0&&!limit1){
                
                red=1;
                
                green=1;    
                
                data=0x20;
                
                send_data(data);
                
            }else if(!limit0&&limit1){
                
                red=0;
                
                green=1;
                
                    data=0x22;
                    
                
                send_data(data);
                
            }else if(limit0&&!limit1){
                
                red=1;
                
                green=0;
                
                data=0x24;
                
                send_data(data);
                
            }
            
            if(!limit2&&!limit3){
                
                green=1;
            
                red=1;

                data=0x26;
                
                send_data(data);
                
            }else if(!limit2&&limit3){
                
                green=1;
                
                red=0;
                
                data=0x28;
                
                send_data(data);
                
            }else if(limit2&&!limit3){
                
                green=0;
                
                red=1;
                
                    data=0x30;
                    
                
                send_data(data);
                 
            }
            
             if(!limit4){
                
                red=1;
                
                green=0;
                
                data=0x32;
                
                send_data(data);
                
            }
            
             if(!limit5){
                
                red=0;
                
                green=1;
                
                data=0x34;
                
                send_data(data);

            }
             if(!limit6){
                
                red=1;
                
                green=0;
                
                data=0x36;
                
                send_data(data);
                
            }
            
            
             if(!limit7&&data==0x40){
                
                red=0;
                
                green=1;
                
                data=0x38;
                
                send_data(data);
                
            }
            
            if(limit0&&limit1&&limit2&&limit3&&limit4&&limit5&&limit6&&limit7){
                
                red=0;
                
                green=0;
                
                data=0x40;
                
                send_data(data);
                
            }
         pc.printf("%c\n",data);
            
        }
        
    }

//rs232通信
void send_data(char send){
    master.putc(send);
    wait(0.005);
    }