手動機 ヌクレオ用のプログラムです

Dependencies:   mbed

Fork of F3RC_syudou_slave_3 by F3RC1班

Revision:
1:dfabac3b39e9
Parent:
0:d0441e7d5ea3
Child:
2:96509fc6e151
--- a/main.cpp	Mon Aug 21 04:57:03 2017 +0000
+++ b/main.cpp	Wed Aug 23 03:33:55 2017 +0000
@@ -2,22 +2,24 @@
 
 Serial pc(USBTX,USBRX);
 SPISlave spi(PC_12,PC_11,PC_10,PA_13);
-DigitalOut photo_1(PC_2);
-DigitalOut photo_2(PC_3);
-DigitalOut moter_1(PA_10);
-DigitalOut moter_2(PA_2);
+PwmOut moter_1(PA_10);
+PwmOut moter_2(PA_2);
 DigitalOut cyli_1(PB_5);
 DigitalOut cyli_2(PB_3);
 DigitalOut cyli_3(PA_10);
+//フォトトランジスタ上
+DigitalIn photo_1(PC_2);
+//フォトトランジスタ下
+DigitalIn photo_2(PC_3);
 
-int a,b,c,d,e,f,g,h,i,j;
+int a,b,c,d,e,f,g,h;
 
 //モーターの出力の設定
 double moter_power = 0.7;
 
 int main()
 {
-    spi.format(16,3);
+    spi.format(8,3);
     spi.frequency(1000000);
 
     while(1) {
@@ -32,57 +34,54 @@
             int f = (spi.read() & 0b100000)>>5;
             int g = (spi.read() & 0b1000000)>>6;
             int h = (spi.read() & 0b10000000)>>7;
-            int i = (spi.read() & 0b100000000)>>8;
-            int j = (spi.read() & 0b1000000000)>>9;
-            pc.printf("a:%d\tb:%d\tc:%d\td:%d\te:%d\tf:%d\tg:%d\th:%d\ti:%d\tj:%d\r\n",a,b,c,d,spi.read());
+            
+            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());
 
         }
-//フォトトランジスタ1
-        if(a == 1) {
-            photo_1=1;
-        } else {
-            photo_1=0;
-        }
+/*フォトトランジスタ1
+        if() {//上で折り返し
+            moter_1=0;
+            moter_2=moter_power;
+        } 
 
 //フォトトランジスタ2
-        if(b == 1) {
-            photo_2=1;
-        } else {
-            photo_2=0;
-        }
+        if() {//下で折り返し
+            moter_1=moter_power;
+            moter_2=0;
+        } */
 
 //腕1 上昇下降
-        if(c == 1) {
-            moter_1=1;
+        if(a == 1) {//上昇
+            moter_1=moter_power;
             moter_2=0;
-        } else if(d == 1) {
+        } else if(b == 1) {//下降
             moter_1=0;
-            moter_2=1;
+            moter_2=moter_power;
         } else {
             moter_1=0;
             moter_2=0;
         }
 
 //腕1 開閉
-        if(e == 1) {
+        if(c == 1) {
             cyli_1=1;
-        } else if(f == 1) {
+        } else if(d == 1) {
             cyli_1=0;
         }
 
 //腕2 上昇下降
-        if(g == 1) {
+        if(e == 1) {
             cyli_2=1;
         } else if(h == 1) {
             cyli_2=0;
         }
 
 //腕2 開閉
-        if(i == 1) {
+        if(f == 1) {
             cyli_3=1;
-        } else if(j == 1) {
+        } else if(g == 1) {
             cyli_3=0;
-        } 
+        }
     }
 
 }