This program is about limit switches

Dependencies:   mbed

Committer:
shina
Date:
Tue Jun 25 09:21:06 2019 +0000
Revision:
1:08c96d55206d
Parent:
0:28ee674a717f
Child:
2:f64f79a6b5e0
This program is limit switch.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shina 1:08c96d55206d 1 /////////////////////////////////////
shina 1:08c96d55206d 2 /*NHK2019*/
shina 1:08c96d55206d 3 /*Aチーム手動機リミットスイッチ用プログラム*/
shina 1:08c96d55206d 4 ////////////////////////////////////
shina 1:08c96d55206d 5
shina 0:28ee674a717f 6 #include "mbed.h"
shina 0:28ee674a717f 7 Serial master(PC_6,PC_7);
shina 0:28ee674a717f 8 Serial pc(USBTX,USBRX);
shina 1:08c96d55206d 9 DigitalIn limit1(D9);//右上ラック
shina 1:08c96d55206d 10 DigitalIn limit2(D8);//左上ラック
shina 1:08c96d55206d 11 DigitalIn limit3(D7);//右下ラック
shina 1:08c96d55206d 12 DigitalIn limit4(D6);//左下ラック
shina 1:08c96d55206d 13 DigitalIn limit5(D5);//回収機構右
shina 1:08c96d55206d 14 DigitalIn limit6(D4);//回収機構左
shina 1:08c96d55206d 15 DigitalIn limit7(D2);//予備
shina 1:08c96d55206d 16 DigitalOut green(D12);//電源確認
shina 1:08c96d55206d 17 DigitalOut yellow(D11);//通信確認
shina 1:08c96d55206d 18 DigitalOut red(D10);//動作確認
shina 1:08c96d55206d 19
shina 1:08c96d55206d 20 //データ格納用変数
shina 0:28ee674a717f 21 char data;
shina 1:08c96d55206d 22
shina 1:08c96d55206d 23 //関数プロトタイプ宣言
shina 0:28ee674a717f 24 void send_data(char send);
shina 1:08c96d55206d 25
shina 1:08c96d55206d 26 //main()関数
shina 0:28ee674a717f 27 int main(){
shina 0:28ee674a717f 28
shina 0:28ee674a717f 29 green=1;
shina 0:28ee674a717f 30
shina 0:28ee674a717f 31 limit1.mode(PullUp);
shina 0:28ee674a717f 32
shina 0:28ee674a717f 33 limit2.mode(PullUp);
shina 0:28ee674a717f 34
shina 0:28ee674a717f 35 limit3.mode(PullUp);
shina 0:28ee674a717f 36
shina 0:28ee674a717f 37 limit4.mode(PullUp);
shina 0:28ee674a717f 38
shina 0:28ee674a717f 39 limit5.mode(PullUp);
shina 0:28ee674a717f 40
shina 0:28ee674a717f 41 limit6.mode(PullUp);
shina 0:28ee674a717f 42
shina 0:28ee674a717f 43 limit7.mode(PullUp);
shina 0:28ee674a717f 44
shina 0:28ee674a717f 45 while(true){
shina 0:28ee674a717f 46
shina 1:08c96d55206d 47 if(!limit1&&!limit2){
shina 0:28ee674a717f 48
shina 0:28ee674a717f 49 red=1;
shina 0:28ee674a717f 50
shina 0:28ee674a717f 51 data=0x20;
shina 0:28ee674a717f 52
shina 0:28ee674a717f 53 send_data(data);
shina 0:28ee674a717f 54
shina 1:08c96d55206d 55 }else if(!limit1&&limit2){
shina 1:08c96d55206d 56
shina 1:08c96d55206d 57 red=1;
shina 1:08c96d55206d 58
shina 1:08c96d55206d 59 data=0x22;
shina 1:08c96d55206d 60
shina 1:08c96d55206d 61 send_data(data);
shina 1:08c96d55206d 62
shina 1:08c96d55206d 63 }else if(limit1&&!limit2){
shina 0:28ee674a717f 64
shina 0:28ee674a717f 65 red=1;
shina 0:28ee674a717f 66
shina 0:28ee674a717f 67 data=0x24;
shina 0:28ee674a717f 68
shina 0:28ee674a717f 69 send_data(data);
shina 0:28ee674a717f 70
shina 1:08c96d55206d 71 }else if(!limit3&&!limit4){
shina 1:08c96d55206d 72
shina 1:08c96d55206d 73 red=1;
shina 1:08c96d55206d 74
shina 1:08c96d55206d 75 data=0x26;
shina 1:08c96d55206d 76
shina 1:08c96d55206d 77 send_data(data);
shina 1:08c96d55206d 78
shina 1:08c96d55206d 79 }else if(!limit3&&limit4){
shina 1:08c96d55206d 80
shina 1:08c96d55206d 81 red=1;
shina 1:08c96d55206d 82
shina 1:08c96d55206d 83 data=0x28;
shina 1:08c96d55206d 84
shina 1:08c96d55206d 85 send_data(data);
shina 1:08c96d55206d 86
shina 1:08c96d55206d 87 }else if(limit3&&!limit4){
shina 1:08c96d55206d 88
shina 1:08c96d55206d 89 red=1;
shina 1:08c96d55206d 90
shina 1:08c96d55206d 91 data=0x30;
shina 1:08c96d55206d 92
shina 1:08c96d55206d 93 send_data(data);
shina 1:08c96d55206d 94
shina 0:28ee674a717f 95 }else if(!limit5){
shina 0:28ee674a717f 96
shina 0:28ee674a717f 97 red=1;
shina 0:28ee674a717f 98
shina 1:08c96d55206d 99 data=0x32;
shina 0:28ee674a717f 100
shina 0:28ee674a717f 101 send_data(data);
shina 0:28ee674a717f 102
shina 0:28ee674a717f 103 }else if(!limit6){
shina 0:28ee674a717f 104
shina 0:28ee674a717f 105 red=1;
shina 0:28ee674a717f 106
shina 1:08c96d55206d 107 data=0x34;
shina 0:28ee674a717f 108
shina 0:28ee674a717f 109 send_data(data);
shina 0:28ee674a717f 110
shina 0:28ee674a717f 111 }else if(!limit7){
shina 0:28ee674a717f 112
shina 0:28ee674a717f 113 red=1;
shina 0:28ee674a717f 114
shina 1:08c96d55206d 115 data=0x36;
shina 0:28ee674a717f 116
shina 0:28ee674a717f 117 send_data(data);
shina 0:28ee674a717f 118
shina 0:28ee674a717f 119 }else{
shina 0:28ee674a717f 120
shina 0:28ee674a717f 121 red=0;
shina 0:28ee674a717f 122
shina 1:08c96d55206d 123 data=0x38;
shina 0:28ee674a717f 124
shina 0:28ee674a717f 125 send_data(data);
shina 0:28ee674a717f 126
shina 0:28ee674a717f 127 }
shina 0:28ee674a717f 128
shina 0:28ee674a717f 129
shina 0:28ee674a717f 130 }
shina 0:28ee674a717f 131
shina 0:28ee674a717f 132 }
shina 0:28ee674a717f 133
shina 1:08c96d55206d 134 //rs232通信
shina 0:28ee674a717f 135 void send_data(char send){
shina 0:28ee674a717f 136 yellow=1;
shina 0:28ee674a717f 137 master.putc(send);
shina 0:28ee674a717f 138 wait(0.005);
shina 0:28ee674a717f 139 }