手動機 ヌクレオ用のプログラムです
Dependencies: mbed
Fork of F3RC_syudou_slave by
Diff: main.cpp
- Revision:
- 4:5ba58456c3ee
- Parent:
- 3:1a3ed86511d3
- Child:
- 5:72e5a850678a
--- a/main.cpp Thu Aug 24 04:49:21 2017 +0000 +++ b/main.cpp Fri Aug 25 12:23:46 2017 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" Serial pc(USBTX,USBRX); -SPISlave spi(PA_7,PA_6,PA_5,PA_4); +BusIn in(PA_7,PA_6,PA_5,PA_4); PwmOut moter_1(PB_14); PwmOut moter_2(PB_15); DigitalOut cyli_1(PB_5); @@ -12,7 +12,7 @@ //フォトインタラプタ下 InterruptIn photo_2(PC_3); -int L_up,L_down,L_open,L_close,R_up,R_down,R_open,R_close; +int num; //モーターの出力の設定 double moter_power = 0.7; @@ -58,8 +58,7 @@ } int main() { - spi.format(8,3); - spi.frequency(1000000); + //フォトインタラプタ1 photo_1.rise(&photo_1_rise); @@ -70,52 +69,38 @@ photo_2.fall(&photo_2_fall); while(1) { - if(spi.receive()) { - - int L_up = spi.read() & 0b1; - int L_down = (spi.read() & 0b10)>>1; - int L_open = (spi.read() & 0b100)>>2; - int L_close = (spi.read() & 0b1000)>>3; - int R_up = (spi.read() & 0b10000)>>4; - int R_down = (spi.read() & 0b100000)>>5; - int R_open = (spi.read() & 0b1000000)>>6; - int R_close = (spi.read() & 0b10000000)>>7; - -//spiの値プリント - pc.printf("L_up:%d\tL_down:%d\tL_open:%d\tL_close:%d\t\nR_up:%d\tR_down:%d\tR_open:%d\tR_close:%d\tsend:%d\r\n",L_up,L_down,L_open,L_close,R_up,R_down,R_open,R_close,spi.read()); - - } + num=in; //腕1 上昇下降 - if(L_up == 1 && up_flag==1) {//上昇 + if(num == 1 && up_flag==1) {//上昇 up(); - } else if(L_down == 1 && down_flag==1) {//下降 + } else if(num == 2 && down_flag==1) {//下降 down(); } else { stop(); } //腕1 開閉 - if(L_open == 1) { + if(num == 3) { cyli_1=1; - } else if(L_close == 1) { + } else if(num == 4) { cyli_1=0; } //腕2 上昇下降 - if(R_up == 1) { + if(num == 5) { cyli_2=1; - } else if(R_down == 1) { + } else if(num == 6) { cyli_2=0; } //腕2 開閉 - if(R_open == 1) { + if(num == 7) { cyli_3=1; - } else if(R_close == 1) { + } else if(num == 8) { cyli_3=0; } + pc.printf("%d\n\r",num); } - }