This program is about limit switches11_18version.
Dependencies: mbed
main.cpp@3:7bbcd64e7127, 2019-11-18 (annotated)
- Committer:
- shina
- Date:
- Mon Nov 18 06:20:56 2019 +0000
- Revision:
- 3:7bbcd64e7127
- Parent:
- 2:f64f79a6b5e0
NHK2019manual limitswitch program 11/18version
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 | 3:7bbcd64e7127 | 22 | char data=0x00; |
shina | 1:08c96d55206d | 23 | |
shina | 2:f64f79a6b5e0 | 24 | |
shina | 2:f64f79a6b5e0 | 25 | |
shina | 1:08c96d55206d | 26 | //関数プロトタイプ宣言 |
shina | 0:28ee674a717f | 27 | void send_data(char send); |
shina | 1:08c96d55206d | 28 | |
shina | 1:08c96d55206d | 29 | //main()関数 |
shina | 3:7bbcd64e7127 | 30 | int main() |
shina | 3:7bbcd64e7127 | 31 | { |
shina | 0:28ee674a717f | 32 | |
shina | 3:7bbcd64e7127 | 33 | master.baud(115200); |
shina | 3:7bbcd64e7127 | 34 | pc.baud(115200); |
shina | 3:7bbcd64e7127 | 35 | |
shina | 3:7bbcd64e7127 | 36 | limit0.mode(PullUp); |
shina | 3:7bbcd64e7127 | 37 | |
shina | 0:28ee674a717f | 38 | limit1.mode(PullUp); |
shina | 3:7bbcd64e7127 | 39 | |
shina | 0:28ee674a717f | 40 | limit2.mode(PullUp); |
shina | 3:7bbcd64e7127 | 41 | |
shina | 0:28ee674a717f | 42 | limit3.mode(PullUp); |
shina | 3:7bbcd64e7127 | 43 | |
shina | 0:28ee674a717f | 44 | limit4.mode(PullUp); |
shina | 3:7bbcd64e7127 | 45 | |
shina | 0:28ee674a717f | 46 | limit5.mode(PullUp); |
shina | 3:7bbcd64e7127 | 47 | |
shina | 0:28ee674a717f | 48 | limit6.mode(PullUp); |
shina | 3:7bbcd64e7127 | 49 | |
shina | 0:28ee674a717f | 50 | limit7.mode(PullUp); |
shina | 3:7bbcd64e7127 | 51 | |
shina | 3:7bbcd64e7127 | 52 | while(true) { |
shina | 0:28ee674a717f | 53 | |
shina | 3:7bbcd64e7127 | 54 | red=1; |
shina | 2:f64f79a6b5e0 | 55 | |
shina | 3:7bbcd64e7127 | 56 | if(!limit0) { |
shina | 3:7bbcd64e7127 | 57 | data = data | 0x01; |
shina | 3:7bbcd64e7127 | 58 | } else { |
shina | 3:7bbcd64e7127 | 59 | data = data & 0b11111110; |
shina | 3:7bbcd64e7127 | 60 | } |
shina | 3:7bbcd64e7127 | 61 | if(!limit1) { |
shina | 3:7bbcd64e7127 | 62 | data = data | 0x02; |
shina | 3:7bbcd64e7127 | 63 | } else { |
shina | 3:7bbcd64e7127 | 64 | data = data & 0b11111101; |
shina | 3:7bbcd64e7127 | 65 | } |
shina | 3:7bbcd64e7127 | 66 | if(!limit2) { |
shina | 3:7bbcd64e7127 | 67 | data = data | 0x04; |
shina | 3:7bbcd64e7127 | 68 | } else { |
shina | 3:7bbcd64e7127 | 69 | data = data & 0b11111011; |
shina | 3:7bbcd64e7127 | 70 | } |
shina | 3:7bbcd64e7127 | 71 | if(!limit3) { |
shina | 3:7bbcd64e7127 | 72 | data = data | 0x08; |
shina | 3:7bbcd64e7127 | 73 | } else { |
shina | 3:7bbcd64e7127 | 74 | data = data & 0b11110111; |
shina | 3:7bbcd64e7127 | 75 | } |
shina | 3:7bbcd64e7127 | 76 | if(!limit4) { |
shina | 3:7bbcd64e7127 | 77 | data = data | 0x10; |
shina | 3:7bbcd64e7127 | 78 | } else { |
shina | 3:7bbcd64e7127 | 79 | data = data & 0b11101111; |
shina | 3:7bbcd64e7127 | 80 | } |
shina | 3:7bbcd64e7127 | 81 | if(!limit5) { |
shina | 3:7bbcd64e7127 | 82 | data = data | 0x20; |
shina | 3:7bbcd64e7127 | 83 | green=1; |
shina | 3:7bbcd64e7127 | 84 | } else { |
shina | 3:7bbcd64e7127 | 85 | data = data & 0b11011111; |
shina | 3:7bbcd64e7127 | 86 | green=0; |
shina | 3:7bbcd64e7127 | 87 | } |
shina | 3:7bbcd64e7127 | 88 | if(!limit6) { |
shina | 3:7bbcd64e7127 | 89 | data = data | 0x40; |
shina | 3:7bbcd64e7127 | 90 | } else { |
shina | 3:7bbcd64e7127 | 91 | data = data & 0b10111111; |
shina | 3:7bbcd64e7127 | 92 | } |
shina | 3:7bbcd64e7127 | 93 | if(!limit7) { |
shina | 3:7bbcd64e7127 | 94 | data = data | 0x80; |
shina | 3:7bbcd64e7127 | 95 | } else { |
shina | 3:7bbcd64e7127 | 96 | data = data & 0b01111111; |
shina | 0:28ee674a717f | 97 | } |
shina | 0:28ee674a717f | 98 | |
shina | 3:7bbcd64e7127 | 99 | |
shina | 3:7bbcd64e7127 | 100 | |
shina | 3:7bbcd64e7127 | 101 | |
shina | 3:7bbcd64e7127 | 102 | send_data(data); |
shina | 3:7bbcd64e7127 | 103 | |
shina | 3:7bbcd64e7127 | 104 | red=0; |
shina | 3:7bbcd64e7127 | 105 | |
shina | 3:7bbcd64e7127 | 106 | pc.printf("0x%x\n",data); |
shina | 3:7bbcd64e7127 | 107 | |
shina | 0:28ee674a717f | 108 | } |
shina | 0:28ee674a717f | 109 | |
shina | 3:7bbcd64e7127 | 110 | } |
shina | 3:7bbcd64e7127 | 111 | |
shina | 1:08c96d55206d | 112 | //rs232通信 |
shina | 3:7bbcd64e7127 | 113 | void send_data(char send) |
shina | 3:7bbcd64e7127 | 114 | { |
shina | 0:28ee674a717f | 115 | master.putc(send); |
shina | 3:7bbcd64e7127 | 116 | wait(0.02); |
shina | 3:7bbcd64e7127 | 117 | } |