yuto kawamura
/
F3RC_syudou_slave
手動機 ヌクレオ用のプログラムです
Fork of F3RC_syudou_slave_3 by
main.cpp@1:dfabac3b39e9, 2017-08-23 (annotated)
- Committer:
- yuto17320508
- Date:
- Wed Aug 23 03:33:55 2017 +0000
- Revision:
- 1:dfabac3b39e9
- Parent:
- 0:d0441e7d5ea3
- Child:
- 2:96509fc6e151
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuto17320508 | 0:d0441e7d5ea3 | 1 | #include "mbed.h" |
yuto17320508 | 0:d0441e7d5ea3 | 2 | |
yuto17320508 | 0:d0441e7d5ea3 | 3 | Serial pc(USBTX,USBRX); |
yuto17320508 | 0:d0441e7d5ea3 | 4 | SPISlave spi(PC_12,PC_11,PC_10,PA_13); |
yuto17320508 | 1:dfabac3b39e9 | 5 | PwmOut moter_1(PA_10); |
yuto17320508 | 1:dfabac3b39e9 | 6 | PwmOut moter_2(PA_2); |
yuto17320508 | 0:d0441e7d5ea3 | 7 | DigitalOut cyli_1(PB_5); |
yuto17320508 | 0:d0441e7d5ea3 | 8 | DigitalOut cyli_2(PB_3); |
yuto17320508 | 0:d0441e7d5ea3 | 9 | DigitalOut cyli_3(PA_10); |
yuto17320508 | 1:dfabac3b39e9 | 10 | //フォトトランジスタ上 |
yuto17320508 | 1:dfabac3b39e9 | 11 | DigitalIn photo_1(PC_2); |
yuto17320508 | 1:dfabac3b39e9 | 12 | //フォトトランジスタ下 |
yuto17320508 | 1:dfabac3b39e9 | 13 | DigitalIn photo_2(PC_3); |
yuto17320508 | 0:d0441e7d5ea3 | 14 | |
yuto17320508 | 1:dfabac3b39e9 | 15 | int a,b,c,d,e,f,g,h; |
yuto17320508 | 0:d0441e7d5ea3 | 16 | |
yuto17320508 | 0:d0441e7d5ea3 | 17 | //モーターの出力の設定 |
yuto17320508 | 0:d0441e7d5ea3 | 18 | double moter_power = 0.7; |
yuto17320508 | 0:d0441e7d5ea3 | 19 | |
yuto17320508 | 0:d0441e7d5ea3 | 20 | int main() |
yuto17320508 | 0:d0441e7d5ea3 | 21 | { |
yuto17320508 | 1:dfabac3b39e9 | 22 | spi.format(8,3); |
yuto17320508 | 0:d0441e7d5ea3 | 23 | spi.frequency(1000000); |
yuto17320508 | 0:d0441e7d5ea3 | 24 | |
yuto17320508 | 0:d0441e7d5ea3 | 25 | while(1) { |
yuto17320508 | 0:d0441e7d5ea3 | 26 | |
yuto17320508 | 0:d0441e7d5ea3 | 27 | if(spi.receive()) { |
yuto17320508 | 0:d0441e7d5ea3 | 28 | |
yuto17320508 | 0:d0441e7d5ea3 | 29 | int a = spi.read() & 0b1; |
yuto17320508 | 0:d0441e7d5ea3 | 30 | int b = (spi.read() & 0b10)>>1; |
yuto17320508 | 0:d0441e7d5ea3 | 31 | int c = (spi.read() & 0b100)>>2; |
yuto17320508 | 0:d0441e7d5ea3 | 32 | int d = (spi.read() & 0b1000)>>3; |
yuto17320508 | 0:d0441e7d5ea3 | 33 | int e = (spi.read() & 0b10000)>>4; |
yuto17320508 | 0:d0441e7d5ea3 | 34 | int f = (spi.read() & 0b100000)>>5; |
yuto17320508 | 0:d0441e7d5ea3 | 35 | int g = (spi.read() & 0b1000000)>>6; |
yuto17320508 | 0:d0441e7d5ea3 | 36 | int h = (spi.read() & 0b10000000)>>7; |
yuto17320508 | 1:dfabac3b39e9 | 37 | |
yuto17320508 | 1:dfabac3b39e9 | 38 | pc.printf("a:%d\tb:%d\tc:%d\td:%d\te:%d\tf:%d\tg:%d\th:%d\r\n",a,b,c,d,e,f,g,h,spi.read()); |
yuto17320508 | 0:d0441e7d5ea3 | 39 | |
yuto17320508 | 0:d0441e7d5ea3 | 40 | } |
yuto17320508 | 1:dfabac3b39e9 | 41 | /*フォトトランジスタ1 |
yuto17320508 | 1:dfabac3b39e9 | 42 | if() {//上で折り返し |
yuto17320508 | 1:dfabac3b39e9 | 43 | moter_1=0; |
yuto17320508 | 1:dfabac3b39e9 | 44 | moter_2=moter_power; |
yuto17320508 | 1:dfabac3b39e9 | 45 | } |
yuto17320508 | 0:d0441e7d5ea3 | 46 | |
yuto17320508 | 0:d0441e7d5ea3 | 47 | //フォトトランジスタ2 |
yuto17320508 | 1:dfabac3b39e9 | 48 | if() {//下で折り返し |
yuto17320508 | 1:dfabac3b39e9 | 49 | moter_1=moter_power; |
yuto17320508 | 1:dfabac3b39e9 | 50 | moter_2=0; |
yuto17320508 | 1:dfabac3b39e9 | 51 | } */ |
yuto17320508 | 0:d0441e7d5ea3 | 52 | |
yuto17320508 | 0:d0441e7d5ea3 | 53 | //腕1 上昇下降 |
yuto17320508 | 1:dfabac3b39e9 | 54 | if(a == 1) {//上昇 |
yuto17320508 | 1:dfabac3b39e9 | 55 | moter_1=moter_power; |
yuto17320508 | 0:d0441e7d5ea3 | 56 | moter_2=0; |
yuto17320508 | 1:dfabac3b39e9 | 57 | } else if(b == 1) {//下降 |
yuto17320508 | 0:d0441e7d5ea3 | 58 | moter_1=0; |
yuto17320508 | 1:dfabac3b39e9 | 59 | moter_2=moter_power; |
yuto17320508 | 0:d0441e7d5ea3 | 60 | } else { |
yuto17320508 | 0:d0441e7d5ea3 | 61 | moter_1=0; |
yuto17320508 | 0:d0441e7d5ea3 | 62 | moter_2=0; |
yuto17320508 | 0:d0441e7d5ea3 | 63 | } |
yuto17320508 | 0:d0441e7d5ea3 | 64 | |
yuto17320508 | 0:d0441e7d5ea3 | 65 | //腕1 開閉 |
yuto17320508 | 1:dfabac3b39e9 | 66 | if(c == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 67 | cyli_1=1; |
yuto17320508 | 1:dfabac3b39e9 | 68 | } else if(d == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 69 | cyli_1=0; |
yuto17320508 | 0:d0441e7d5ea3 | 70 | } |
yuto17320508 | 0:d0441e7d5ea3 | 71 | |
yuto17320508 | 0:d0441e7d5ea3 | 72 | //腕2 上昇下降 |
yuto17320508 | 1:dfabac3b39e9 | 73 | if(e == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 74 | cyli_2=1; |
yuto17320508 | 0:d0441e7d5ea3 | 75 | } else if(h == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 76 | cyli_2=0; |
yuto17320508 | 0:d0441e7d5ea3 | 77 | } |
yuto17320508 | 0:d0441e7d5ea3 | 78 | |
yuto17320508 | 0:d0441e7d5ea3 | 79 | //腕2 開閉 |
yuto17320508 | 1:dfabac3b39e9 | 80 | if(f == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 81 | cyli_3=1; |
yuto17320508 | 1:dfabac3b39e9 | 82 | } else if(g == 1) { |
yuto17320508 | 0:d0441e7d5ea3 | 83 | cyli_3=0; |
yuto17320508 | 1:dfabac3b39e9 | 84 | } |
yuto17320508 | 0:d0441e7d5ea3 | 85 | } |
yuto17320508 | 0:d0441e7d5ea3 | 86 | |
yuto17320508 | 0:d0441e7d5ea3 | 87 | } |