マザー 20151028 XBOX-XBEE

Dependencies:   mbed

Fork of Nucleo_PS3_Jikken_XBOX by 2015 robotic contest arakawa A

Revision:
23:d5f7e3dab589
Parent:
22:ab619079fb8d
Child:
24:ee0943b12feb
--- a/main.cpp	Sat Oct 17 05:44:35 2015 +0000
+++ b/main.cpp	Fri Oct 23 10:21:57 2015 +0000
@@ -23,6 +23,7 @@
 #define TNL 150
 #define debugFlag 1
 #define stopCount 33
+#define shotWait 0.3
 
 Serial pc(SERIAL_TX, SERIAL_RX);
 //Serial Dev(D8,D2);//コントローラー
@@ -45,6 +46,7 @@
 void rotate(double setAngle);
 void speed();
 int stopCounter=0;
+bool pushF=false;
 
 void num()//割り込まれたら7回受信
 {
@@ -235,11 +237,11 @@
     int val;
     i2c.frequency(400000); 
     setFCLED(0,0.8,0.8);
-    bool obonFlag=false,pLeftF=false,pRightF=false,btCrF=false,detFinF=false;
+    bool obonFlag=false,pLeftF=false,pRightF=false,btCrF=false,detFinF=false,touchSF=false;
 
     while(true)
     {           
-        //ポール検出モード
+       /* //ポール検出モード
         if(getBt(btTri)&&getBt(btSph)){
             if(deg>devideNum-1);
             else if(deg<17){
@@ -250,34 +252,46 @@
                 //pc.printf("L\r\n");
                 detFinF=detectPole(TNL);
             }
-        }
-        
-        //射出
-        if(getBt(btL)&&obonFlag){
-            kRed=shotToDenziben(airReg,1,1,airAddr);
-            wait(0.5f);
-            kRed=shotToDenziben(airReg,0,1,airAddr);
-            kRed=0;
-        }
+        }*/
         
-        //射出
-        if(getBt(btR)&&obonFlag){
-            kRed=shotToDenziben(airReg,2,1,airAddr);
-            wait(0.5f);
-            kRed=shotToDenziben(airReg,0,1,airAddr);
-            //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2));
-            //i2c.write(airAddr,cmd,2);
-            kRed=0;
-        }
+        do{
+            bool l=getBt(btL),r=getBt(btR),t=getBt(btTri);
+            if(!l&&!r&&!t)
+                pushF=false;
+            if(pushF||!obonFlag)
+                break;
+                
+            //射出
+            if(l){
+                pushF=true;
+                kRed=shotToDenziben(airReg,1,1,airAddr);
+                wait(shotWait);
+                kRed=shotToDenziben(airReg,0,1,airAddr);
+                kRed=0;
+            }
+            
+            //射出
+            else if(r){
+                pushF=true;
+                kRed=shotToDenziben(airReg,2,1,airAddr);
+                wait(shotWait);
+                kRed=shotToDenziben(airReg,0,1,airAddr);
+                //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2));
+                //i2c.write(airAddr,cmd,2);
+                kRed=0;
+            }
+            
+            //射出
+            else if(t){
+                pushF=true;
+                kRed=shotToDenziben(airReg,4,1,airAddr);
+                wait(shotWait);
+                kRed=shotToDenziben(airReg,0,1,airAddr);
+                kRed=0;
+            }
+                
+        }while(false);
         
-        //射出
-        if(getBt(btTri)&&obonFlag){
-            kRed=shotToDenziben(airReg,4,1,airAddr);
-            wait(0.5f);
-            kRed=shotToDenziben(airReg,0,1,airAddr);
-            kRed=0;
-        }
-
         //レーザーポインタ
         if(getBt(btSqa)&&sqf){
             sqf=0;
@@ -288,27 +302,32 @@
             sqf=1;
             
         //タッチセンサ
-        if(((int)DATA[1]&12)==12){
-            bValue=0;gValue=0.8;rValue=0;
+        if(((int)DATA[1]&12)==12&&!touchSF){
+            touchSF=true;
+            gValue=0.8;
         }
-        
+        else if(!((int)DATA[1]&12)==12){
+            touchSF=false;
+            gValue=0;bValue=0.8;
+        }
         //お盆回し
         if(getPress(presUp)){
             obonFlag=true;
             Mechanum.putc(162);
-            rValue=0.8;gValue=0;bValue=0.8;
+            rValue=0.8;
             kRed=0;
             wait(0.2);
         }
         else if(getPress(presDown)){
             Mechanum.putc(163);
-            bValue=0.8f;gValue=0;rValue=0;
+            rValue=0;
             obonFlag=false;
             kRed=0;
             wait(0.2);
         }         
         
         deg=devidePoint((double)DATA[3],(double)DATA[2],15,360/devideNum);
+        
         if(getPress(btSel)||(detFinF&&deg!=devideNum)){
             detFinF=false;
             Mechanum.putc(163);