敦哉 品川
/
limit_switch
This program is about limit switches
main.cpp@2:f64f79a6b5e0, 2019-09-05 (annotated)
- Committer:
- shina
- Date:
- Thu Sep 05 09:42:23 2019 +0000
- Revision:
- 2:f64f79a6b5e0
- Parent:
- 1:08c96d55206d
- Child:
- 3:7bbcd64e7127
limitswitch
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:f64f79a6b5e0 | 9 | DigitalIn limit0(D10);//右上ラック |
shina | 2:f64f79a6b5e0 | 10 | DigitalIn limit1(D9);//左上ラック |
shina | 2:f64f79a6b5e0 | 11 | DigitalIn limit2(D8);//右下ラック |
shina | 2:f64f79a6b5e0 | 12 | DigitalIn limit3(D7);//左下ラック |
shina | 2:f64f79a6b5e0 | 13 | |
shina | 2:f64f79a6b5e0 | 14 | DigitalIn limit4(D6);//回収機構右 |
shina | 2:f64f79a6b5e0 | 15 | DigitalIn limit5(D5);//回収機構左 |
shina | 2:f64f79a6b5e0 | 16 | DigitalIn limit6(D4);//吐き出し1 |
shina | 2:f64f79a6b5e0 | 17 | DigitalIn limit7(D2);//吐き出し2 |
shina | 1:08c96d55206d | 18 | DigitalOut green(D12);//電源確認 |
shina | 2:f64f79a6b5e0 | 19 | DigitalOut red(D11);//動作確認 |
shina | 2:f64f79a6b5e0 | 20 | |
shina | 1:08c96d55206d | 21 | |
shina | 1:08c96d55206d | 22 | //データ格納用変数 |
shina | 0:28ee674a717f | 23 | char data; |
shina | 1:08c96d55206d | 24 | |
shina | 2:f64f79a6b5e0 | 25 | |
shina | 2:f64f79a6b5e0 | 26 | |
shina | 1:08c96d55206d | 27 | //関数プロトタイプ宣言 |
shina | 0:28ee674a717f | 28 | void send_data(char send); |
shina | 1:08c96d55206d | 29 | |
shina | 1:08c96d55206d | 30 | //main()関数 |
shina | 0:28ee674a717f | 31 | int main(){ |
shina | 0:28ee674a717f | 32 | |
shina | 2:f64f79a6b5e0 | 33 | |
shina | 2:f64f79a6b5e0 | 34 | limit0.mode(PullUp); |
shina | 0:28ee674a717f | 35 | |
shina | 0:28ee674a717f | 36 | limit1.mode(PullUp); |
shina | 0:28ee674a717f | 37 | |
shina | 0:28ee674a717f | 38 | limit2.mode(PullUp); |
shina | 0:28ee674a717f | 39 | |
shina | 0:28ee674a717f | 40 | limit3.mode(PullUp); |
shina | 0:28ee674a717f | 41 | |
shina | 0:28ee674a717f | 42 | limit4.mode(PullUp); |
shina | 0:28ee674a717f | 43 | |
shina | 0:28ee674a717f | 44 | limit5.mode(PullUp); |
shina | 0:28ee674a717f | 45 | |
shina | 0:28ee674a717f | 46 | limit6.mode(PullUp); |
shina | 0:28ee674a717f | 47 | |
shina | 0:28ee674a717f | 48 | limit7.mode(PullUp); |
shina | 0:28ee674a717f | 49 | |
shina | 0:28ee674a717f | 50 | while(true){ |
shina | 0:28ee674a717f | 51 | |
shina | 2:f64f79a6b5e0 | 52 | if(!limit0&&!limit1){ |
shina | 0:28ee674a717f | 53 | |
shina | 0:28ee674a717f | 54 | red=1; |
shina | 0:28ee674a717f | 55 | |
shina | 2:f64f79a6b5e0 | 56 | green=1; |
shina | 2:f64f79a6b5e0 | 57 | |
shina | 0:28ee674a717f | 58 | data=0x20; |
shina | 0:28ee674a717f | 59 | |
shina | 0:28ee674a717f | 60 | send_data(data); |
shina | 0:28ee674a717f | 61 | |
shina | 2:f64f79a6b5e0 | 62 | }else if(!limit0&&limit1){ |
shina | 2:f64f79a6b5e0 | 63 | |
shina | 2:f64f79a6b5e0 | 64 | red=0; |
shina | 2:f64f79a6b5e0 | 65 | |
shina | 2:f64f79a6b5e0 | 66 | green=1; |
shina | 2:f64f79a6b5e0 | 67 | |
shina | 2:f64f79a6b5e0 | 68 | data=0x22; |
shina | 2:f64f79a6b5e0 | 69 | |
shina | 2:f64f79a6b5e0 | 70 | |
shina | 2:f64f79a6b5e0 | 71 | send_data(data); |
shina | 2:f64f79a6b5e0 | 72 | |
shina | 2:f64f79a6b5e0 | 73 | }else if(limit0&&!limit1){ |
shina | 1:08c96d55206d | 74 | |
shina | 1:08c96d55206d | 75 | red=1; |
shina | 1:08c96d55206d | 76 | |
shina | 2:f64f79a6b5e0 | 77 | green=0; |
shina | 0:28ee674a717f | 78 | |
shina | 0:28ee674a717f | 79 | data=0x24; |
shina | 0:28ee674a717f | 80 | |
shina | 0:28ee674a717f | 81 | send_data(data); |
shina | 0:28ee674a717f | 82 | |
shina | 2:f64f79a6b5e0 | 83 | } |
shina | 2:f64f79a6b5e0 | 84 | |
shina | 2:f64f79a6b5e0 | 85 | if(!limit2&&!limit3){ |
shina | 1:08c96d55206d | 86 | |
shina | 2:f64f79a6b5e0 | 87 | green=1; |
shina | 2:f64f79a6b5e0 | 88 | |
shina | 1:08c96d55206d | 89 | red=1; |
shina | 2:f64f79a6b5e0 | 90 | |
shina | 1:08c96d55206d | 91 | data=0x26; |
shina | 1:08c96d55206d | 92 | |
shina | 1:08c96d55206d | 93 | send_data(data); |
shina | 1:08c96d55206d | 94 | |
shina | 2:f64f79a6b5e0 | 95 | }else if(!limit2&&limit3){ |
shina | 1:08c96d55206d | 96 | |
shina | 2:f64f79a6b5e0 | 97 | green=1; |
shina | 2:f64f79a6b5e0 | 98 | |
shina | 2:f64f79a6b5e0 | 99 | red=0; |
shina | 1:08c96d55206d | 100 | |
shina | 1:08c96d55206d | 101 | data=0x28; |
shina | 1:08c96d55206d | 102 | |
shina | 1:08c96d55206d | 103 | send_data(data); |
shina | 1:08c96d55206d | 104 | |
shina | 2:f64f79a6b5e0 | 105 | }else if(limit2&&!limit3){ |
shina | 2:f64f79a6b5e0 | 106 | |
shina | 2:f64f79a6b5e0 | 107 | green=0; |
shina | 1:08c96d55206d | 108 | |
shina | 1:08c96d55206d | 109 | red=1; |
shina | 1:08c96d55206d | 110 | |
shina | 2:f64f79a6b5e0 | 111 | data=0x30; |
shina | 2:f64f79a6b5e0 | 112 | |
shina | 1:08c96d55206d | 113 | |
shina | 1:08c96d55206d | 114 | send_data(data); |
shina | 2:f64f79a6b5e0 | 115 | |
shina | 2:f64f79a6b5e0 | 116 | } |
shina | 2:f64f79a6b5e0 | 117 | |
shina | 2:f64f79a6b5e0 | 118 | if(!limit4){ |
shina | 0:28ee674a717f | 119 | |
shina | 0:28ee674a717f | 120 | red=1; |
shina | 0:28ee674a717f | 121 | |
shina | 2:f64f79a6b5e0 | 122 | green=0; |
shina | 2:f64f79a6b5e0 | 123 | |
shina | 1:08c96d55206d | 124 | data=0x32; |
shina | 0:28ee674a717f | 125 | |
shina | 0:28ee674a717f | 126 | send_data(data); |
shina | 0:28ee674a717f | 127 | |
shina | 2:f64f79a6b5e0 | 128 | } |
shina | 2:f64f79a6b5e0 | 129 | |
shina | 2:f64f79a6b5e0 | 130 | if(!limit5){ |
shina | 0:28ee674a717f | 131 | |
shina | 2:f64f79a6b5e0 | 132 | red=0; |
shina | 2:f64f79a6b5e0 | 133 | |
shina | 2:f64f79a6b5e0 | 134 | green=1; |
shina | 0:28ee674a717f | 135 | |
shina | 1:08c96d55206d | 136 | data=0x34; |
shina | 0:28ee674a717f | 137 | |
shina | 0:28ee674a717f | 138 | send_data(data); |
shina | 2:f64f79a6b5e0 | 139 | |
shina | 2:f64f79a6b5e0 | 140 | } |
shina | 2:f64f79a6b5e0 | 141 | if(!limit6){ |
shina | 0:28ee674a717f | 142 | |
shina | 0:28ee674a717f | 143 | red=1; |
shina | 0:28ee674a717f | 144 | |
shina | 2:f64f79a6b5e0 | 145 | green=0; |
shina | 2:f64f79a6b5e0 | 146 | |
shina | 1:08c96d55206d | 147 | data=0x36; |
shina | 0:28ee674a717f | 148 | |
shina | 0:28ee674a717f | 149 | send_data(data); |
shina | 0:28ee674a717f | 150 | |
shina | 2:f64f79a6b5e0 | 151 | } |
shina | 2:f64f79a6b5e0 | 152 | |
shina | 2:f64f79a6b5e0 | 153 | |
shina | 2:f64f79a6b5e0 | 154 | if(!limit7&&data==0x40){ |
shina | 0:28ee674a717f | 155 | |
shina | 0:28ee674a717f | 156 | red=0; |
shina | 0:28ee674a717f | 157 | |
shina | 2:f64f79a6b5e0 | 158 | green=1; |
shina | 2:f64f79a6b5e0 | 159 | |
shina | 1:08c96d55206d | 160 | data=0x38; |
shina | 0:28ee674a717f | 161 | |
shina | 0:28ee674a717f | 162 | send_data(data); |
shina | 0:28ee674a717f | 163 | |
shina | 2:f64f79a6b5e0 | 164 | } |
shina | 0:28ee674a717f | 165 | |
shina | 2:f64f79a6b5e0 | 166 | if(limit0&&limit1&&limit2&&limit3&&limit4&&limit5&&limit6&&limit7){ |
shina | 2:f64f79a6b5e0 | 167 | |
shina | 2:f64f79a6b5e0 | 168 | red=0; |
shina | 2:f64f79a6b5e0 | 169 | |
shina | 2:f64f79a6b5e0 | 170 | green=0; |
shina | 2:f64f79a6b5e0 | 171 | |
shina | 2:f64f79a6b5e0 | 172 | data=0x40; |
shina | 2:f64f79a6b5e0 | 173 | |
shina | 2:f64f79a6b5e0 | 174 | send_data(data); |
shina | 2:f64f79a6b5e0 | 175 | |
shina | 2:f64f79a6b5e0 | 176 | } |
shina | 2:f64f79a6b5e0 | 177 | pc.printf("%c\n",data); |
shina | 0:28ee674a717f | 178 | |
shina | 0:28ee674a717f | 179 | } |
shina | 0:28ee674a717f | 180 | |
shina | 0:28ee674a717f | 181 | } |
shina | 0:28ee674a717f | 182 | |
shina | 1:08c96d55206d | 183 | //rs232通信 |
shina | 0:28ee674a717f | 184 | void send_data(char send){ |
shina | 0:28ee674a717f | 185 | master.putc(send); |
shina | 0:28ee674a717f | 186 | wait(0.005); |
shina | 0:28ee674a717f | 187 | } |