マザー 20151028 PS3
Dependencies: mbed
Fork of Nucleo_PS3_Jikken3 by
Diff: main.cpp
- Revision:
- 1:a3bfd422ea9e
- Parent:
- 0:dc587be179e9
- Child:
- 2:c5f038d7be1f
--- a/main.cpp Mon Jul 20 08:57:05 2015 +0000 +++ b/main.cpp Sat Aug 08 06:46:52 2015 +0000 @@ -11,17 +11,21 @@ #define btSqa 7 Serial pc(SERIAL_TX, SERIAL_RX); -Serial Dev(D8,D2);//コントローラー -RawSerial Mechanum(PA_11,PA_12);//メカナム +//Serial Dev(D8,D2);//コントローラー +Serial Dev(PC_6,PA_12);//コンßトローラー +RawSerial Mechanum(D8,D2);//メカナム I2C i2c(D14,D15);//sda,scl const int airAddr=0xA0; +BusOut dI2c(PC_0,PC_1,PC_2,PC_3);//i2cデバッグ int Bflag = 0; DigitalOut myled(LED1);// ,test1(PB_7) ,test2(PA_15) ,test3(PC_13) ,test4(PC_12); +PwmOut Green(D5),Blue(D4),Red(D3); #define N 6 char DATA[N]; void rotate(double setAngle); void speed(); + void num()//割り込まれたら6回受信 { if(Dev.getc()==114){ @@ -111,6 +115,7 @@ { bool btFlag=true,lFlag=false; int vector=130; + Blue=0.8f;Green=0; while(true) { if((((int)DATA[1]&12)==12)&&btFlag){ @@ -119,7 +124,7 @@ btFlag=false; } - else if(!(((int)DATA[1]&1)==1)&&!(((int)DATA[1]&2)==2)&&lFlag){ + else if(((!(int)DATA[1]&1==1)&&(!(int)DATA[1]&2==2))&&lFlag){ vector=72; break; } @@ -128,6 +133,7 @@ wait(0.001f); } btFlag=true;lFlag=false; + Blue=0;Green=0; } @@ -135,8 +141,8 @@ { char DATA[2] = {reg,size}; bool A = i2c.write(airAddr,DATA,2); - A|= i2c.write(airAddr,data,size); - return N; + A|= i2c.write(airAddr,data,size); + return A; } int main() { @@ -146,13 +152,13 @@ char shotL[]={0xC0,0}; char shotR[]={0xE0,0}; Dev.attach(num,Serial::RxIrq);//受信割り込み設定 - + Green=0;Blue=0;Red=0; //pc.printf("Hello World !\n"); double deg; int val; bool shotLf=true,shotRf=true; bool i2cS=true; - i2c.frequency(400000); + i2c.frequency(400000); while(true) { @@ -161,21 +167,23 @@ //printf("DetectMode\r\n"); } if(getBt(btL)&shotLf){ - i2cS=shot(0x02,shotL,1); + dI2c=shot(0x02,shotL,1); wait(0.3f); //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2)); //i2c.write(airAddr,cmd,2); shotLf=false; + dI2c=0; } else if(!getBt(btL)) shotLf=true; if(getBt(btR)&shotRf){ - i2cS=shot(0x02,shotR,1); + dI2c=shot(0x02,shotR,1); wait(0.3f); //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2)); //i2c.write(airAddr,cmd,2); shotRf=false; + dI2c=0; } else if(!getBt(btR)) shotRf=true; @@ -186,6 +194,6 @@ //printf("val:%d\r\n",val); Mechanum.putc(val); wait(0.03f); - //printf("X:%dX1:%d:bt%dval:%di2cS:%d\r\n",(int)DATA[0],(int)DATA[1]&12,getBt(btSqa),val,i2cS); + printf("X:%dX1:%d:bt%dval:%di2cS:%d\r\n",(int)DATA[0],(int)DATA[1],getBt(btSqa),val,i2cS); } } \ No newline at end of file