マザー 20151028 PS3
Dependencies: mbed
Fork of Nucleo_PS3_Jikken3 by
main.cpp@24:ee0943b12feb, 2015-10-28 (annotated)
- Committer:
- nodoame
- Date:
- Wed Oct 28 09:18:09 2015 +0000
- Revision:
- 24:ee0943b12feb
- Parent:
- 23:d5f7e3dab589
PS3; 20151028
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nodoame | 0:dc587be179e9 | 1 | #include "mbed.h" |
nodoame | 0:dc587be179e9 | 2 | #include "math.h" |
nodoame | 0:dc587be179e9 | 3 | #define M_PI 3.1415926535897932384626433832795 |
nodoame | 0:dc587be179e9 | 4 | #define trigL 0 |
nodoame | 0:dc587be179e9 | 5 | #define trigR 1 |
nodoame | 0:dc587be179e9 | 6 | #define btL 2 |
nodoame | 0:dc587be179e9 | 7 | #define btR 3 |
nodoame | 0:dc587be179e9 | 8 | #define btTri 4 |
nodoame | 0:dc587be179e9 | 9 | #define btSph 5 |
nodoame | 0:dc587be179e9 | 10 | #define btCro 6 |
nodoame | 0:dc587be179e9 | 11 | #define btSqa 7 |
nodoame | 20:373fa71ce05b | 12 | #define btSel 0 |
nodoame | 20:373fa71ce05b | 13 | #define presUp 4 |
nodoame | 20:373fa71ce05b | 14 | #define presRight 5 |
nodoame | 20:373fa71ce05b | 15 | #define presDown 6 |
nodoame | 20:373fa71ce05b | 16 | #define presLeft 7 |
nodoame | 4:bae4e2d103d4 | 17 | #define devideNum 32 |
nodoame | 4:bae4e2d103d4 | 18 | #define ED 132 |
nodoame | 6:5171a8245b57 | 19 | #define TD 144//208 |
nodoame | 5:428b7ac86810 | 20 | #define EL 134 |
nodoame | 5:428b7ac86810 | 21 | #define TL 200 |
nodoame | 6:5171a8245b57 | 22 | #define TNR 138//204 |
nodoame | 20:373fa71ce05b | 23 | #define TNL 150 |
nodoame | 11:1ca2498815c9 | 24 | #define debugFlag 1 |
nodoame | 11:1ca2498815c9 | 25 | #define stopCount 33 |
nodoame | 24:ee0943b12feb | 26 | #define shotWait 0.5 |
nodoame | 0:dc587be179e9 | 27 | |
nodoame | 0:dc587be179e9 | 28 | Serial pc(SERIAL_TX, SERIAL_RX); |
nodoame | 1:a3bfd422ea9e | 29 | //Serial Dev(D8,D2);//コントローラー |
nodoame | 3:c290afbacd1c | 30 | Serial Dev(PC_6,PA_12);//コントローラー |
nodoame | 1:a3bfd422ea9e | 31 | RawSerial Mechanum(D8,D2);//メカナム |
nodoame | 0:dc587be179e9 | 32 | I2C i2c(D14,D15);//sda,scl |
nodoame | 5:428b7ac86810 | 33 | //const int airAddr=0x20; |
nodoame | 20:373fa71ce05b | 34 | const int airAddr=0xd0; |
nodoame | 20:373fa71ce05b | 35 | const int airReg=10; |
nodoame | 5:428b7ac86810 | 36 | const int valveAddr=0xC0; |
nodoame | 1:a3bfd422ea9e | 37 | BusOut dI2c(PC_0,PC_1,PC_2,PC_3);//i2cデバッグ |
nodoame | 0:dc587be179e9 | 38 | |
nodoame | 0:dc587be179e9 | 39 | int Bflag = 0; |
nodoame | 0:dc587be179e9 | 40 | DigitalOut myled(LED1);// ,test1(PB_7) ,test2(PA_15) ,test3(PC_13) ,test4(PC_12); |
nodoame | 4:bae4e2d103d4 | 41 | PwmOut Blue(D5),Green(D4),Red(D3); |
nodoame | 4:bae4e2d103d4 | 42 | //PwmOut kRed(A3),kBlue(A1),kGreen(A0); |
nodoame | 4:bae4e2d103d4 | 43 | PwmOut kRed(A3),kBlue(PA_15),kGreen(PB_7); |
nodoame | 5:428b7ac86810 | 44 | #define N 7 |
nodoame | 0:dc587be179e9 | 45 | char DATA[N]; |
nodoame | 0:dc587be179e9 | 46 | void rotate(double setAngle); |
nodoame | 0:dc587be179e9 | 47 | void speed(); |
nodoame | 11:1ca2498815c9 | 48 | int stopCounter=0; |
nodoame | 23:d5f7e3dab589 | 49 | bool pushF=false; |
nodoame | 1:a3bfd422ea9e | 50 | |
nodoame | 5:428b7ac86810 | 51 | void num()//割り込まれたら7回受信 |
nodoame | 0:dc587be179e9 | 52 | { |
nodoame | 0:dc587be179e9 | 53 | if(Dev.getc()==114){ |
nodoame | 0:dc587be179e9 | 54 | //printf("ReceiveCommand\r\n"); |
nodoame | 0:dc587be179e9 | 55 | for(int i = 0 ;i<N ;i++ ) |
nodoame | 0:dc587be179e9 | 56 | { |
nodoame | 0:dc587be179e9 | 57 | DATA[i]=Dev.getc(); |
nodoame | 0:dc587be179e9 | 58 | } |
nodoame | 0:dc587be179e9 | 59 | } |
nodoame | 11:1ca2498815c9 | 60 | stopCounter=0; |
nodoame | 0:dc587be179e9 | 61 | } |
nodoame | 0:dc587be179e9 | 62 | |
nodoame | 0:dc587be179e9 | 63 | bool getBt(int num) |
nodoame | 0:dc587be179e9 | 64 | { |
nodoame | 0:dc587be179e9 | 65 | return (DATA[0]>>num)%2; |
nodoame | 0:dc587be179e9 | 66 | } |
nodoame | 0:dc587be179e9 | 67 | |
nodoame | 5:428b7ac86810 | 68 | bool getPress(int num) |
nodoame | 5:428b7ac86810 | 69 | { |
nodoame | 5:428b7ac86810 | 70 | return (DATA[6]>>num)%2; |
nodoame | 5:428b7ac86810 | 71 | } |
nodoame | 5:428b7ac86810 | 72 | |
nodoame | 0:dc587be179e9 | 73 | double pointToDeg(double y,double x,int threshold)//座標から角度を求める関数thresholdはしきい値 |
nodoame | 0:dc587be179e9 | 74 | { |
nodoame | 0:dc587be179e9 | 75 | if(abs((int)(y-128))<threshold) |
nodoame | 0:dc587be179e9 | 76 | y=128; |
nodoame | 0:dc587be179e9 | 77 | if(abs((int)(x-128))<threshold) |
nodoame | 0:dc587be179e9 | 78 | x=128; |
nodoame | 0:dc587be179e9 | 79 | return atan2(-(y-128),x-128)/M_PI*180;//y軸反転、/PI*180でRadからDeg変換 |
nodoame | 0:dc587be179e9 | 80 | } |
nodoame | 0:dc587be179e9 | 81 | |
nodoame | 20:373fa71ce05b | 82 | int devidePoint(double y,double x,int threshold,float devide) |
nodoame | 0:dc587be179e9 | 83 | { |
nodoame | 0:dc587be179e9 | 84 | double tempX,tempY,dev;//仮のX,Yと分けた角度 |
nodoame | 0:dc587be179e9 | 85 | tempX=(x-128);tempY=(y-128);//それぞれ-128 |
nodoame | 0:dc587be179e9 | 86 | if(abs((int)tempY)<threshold)//しきい値以下なら0にする |
nodoame | 0:dc587be179e9 | 87 | tempY=0; |
nodoame | 0:dc587be179e9 | 88 | if(abs((int)tempX)<threshold) |
nodoame | 0:dc587be179e9 | 89 | tempX=0; |
nodoame | 0:dc587be179e9 | 90 | if(tempX==0&&tempY==0) |
nodoame | 0:dc587be179e9 | 91 | dev=360; |
nodoame | 0:dc587be179e9 | 92 | //printf("X:%lfY:%lfDev:%lf\r\n",tempX,tempY,dev); |
nodoame | 0:dc587be179e9 | 93 | else |
nodoame | 0:dc587be179e9 | 94 | dev=atan2(tempX,-tempY)/M_PI*180;//軸を逆にして代入、Y軸反転 |
nodoame | 0:dc587be179e9 | 95 | return ((dev<0)?(dev+360):(dev))/devide;//分割 |
nodoame | 0:dc587be179e9 | 96 | } |
nodoame | 0:dc587be179e9 | 97 | |
nodoame | 4:bae4e2d103d4 | 98 | int valueForMechanum(int deg,int devide,bool triL,bool triR,bool btSpd) |
nodoame | 0:dc587be179e9 | 99 | { |
nodoame | 0:dc587be179e9 | 100 | bool stpFlag=false,spnFlag=false;//ストップフラグ、スピンフラグ |
nodoame | 0:dc587be179e9 | 101 | int val=0,i;//値、For用 |
nodoame | 0:dc587be179e9 | 102 | for(i=0;i<6;i++){ |
nodoame | 0:dc587be179e9 | 103 | switch(i){ |
nodoame | 0:dc587be179e9 | 104 | case 0: |
nodoame | 4:bae4e2d103d4 | 105 | if(deg!=devide||(triL||triR))//スピンかニュートラル以外なら |
nodoame | 0:dc587be179e9 | 106 | val=1; |
nodoame | 0:dc587be179e9 | 107 | else |
nodoame | 0:dc587be179e9 | 108 | stpFlag=true;//ストップ |
nodoame | 0:dc587be179e9 | 109 | break; |
nodoame | 0:dc587be179e9 | 110 | |
nodoame | 0:dc587be179e9 | 111 | case 1: |
nodoame | 0:dc587be179e9 | 112 | if(stpFlag) |
nodoame | 4:bae4e2d103d4 | 113 | val++; |
nodoame | 0:dc587be179e9 | 114 | else |
nodoame | 0:dc587be179e9 | 115 | val+=btSpd;//スピード |
nodoame | 0:dc587be179e9 | 116 | break; |
nodoame | 0:dc587be179e9 | 117 | |
nodoame | 0:dc587be179e9 | 118 | case 2: |
nodoame | 0:dc587be179e9 | 119 | if(triL||triR){//トリガーのどちらかがONなら |
nodoame | 0:dc587be179e9 | 120 | val++; |
nodoame | 0:dc587be179e9 | 121 | spnFlag=true;//スピンフラグON |
nodoame | 0:dc587be179e9 | 122 | } |
nodoame | 0:dc587be179e9 | 123 | break; |
nodoame | 0:dc587be179e9 | 124 | |
nodoame | 0:dc587be179e9 | 125 | case 5: |
nodoame | 4:bae4e2d103d4 | 126 | val=val<<2;//5bit目から7bit目へ |
nodoame | 0:dc587be179e9 | 127 | if(spnFlag)//トリガーのどちらかの値 |
nodoame | 0:dc587be179e9 | 128 | val+=(triL)?1:0; |
nodoame | 4:bae4e2d103d4 | 129 | else if(!stpFlag)//ジョイスティックの値 |
nodoame | 0:dc587be179e9 | 130 | val+=deg; |
nodoame | 0:dc587be179e9 | 131 | break; |
nodoame | 0:dc587be179e9 | 132 | } |
nodoame | 0:dc587be179e9 | 133 | if(i<5) |
nodoame | 0:dc587be179e9 | 134 | val=val<<1; |
nodoame | 0:dc587be179e9 | 135 | } |
nodoame | 0:dc587be179e9 | 136 | //printf("val:%ddeg:%dtrigL:%dtrigR:%dbtSp:%d\r\n",val,deg,triL,triR,btSpd); |
nodoame | 0:dc587be179e9 | 137 | return val; |
nodoame | 0:dc587be179e9 | 138 | } |
nodoame | 0:dc587be179e9 | 139 | |
nodoame | 20:373fa71ce05b | 140 | bool detectPole(int scVector) |
nodoame | 0:dc587be179e9 | 141 | { |
nodoame | 15:c941d06092ec | 142 | int vector=TD,laser=0; |
nodoame | 20:373fa71ce05b | 143 | bool btFlag=false,canFlag=false,breakFlag=false,stopFlag=false; |
nodoame | 4:bae4e2d103d4 | 144 | Blue=0.0f;Green=0.0f,Red=0.8f; |
nodoame | 0:dc587be179e9 | 145 | while(true) |
nodoame | 20:373fa71ce05b | 146 | { |
nodoame | 20:373fa71ce05b | 147 | if((getBt(btTri)&&getBt(btSph)&&canFlag)||breakFlag) |
nodoame | 20:373fa71ce05b | 148 | return breakFlag; |
nodoame | 20:373fa71ce05b | 149 | else if(!(getBt(btTri)&&getBt(btSph))) |
nodoame | 20:373fa71ce05b | 150 | canFlag=true; |
nodoame | 20:373fa71ce05b | 151 | |
nodoame | 14:aaf2ae25e508 | 152 | //スイッチが押された時 |
nodoame | 20:373fa71ce05b | 153 | if(((int)DATA[1]&12)==12&&!btFlag){ |
nodoame | 5:428b7ac86810 | 154 | wait(0.001f); |
nodoame | 5:428b7ac86810 | 155 | Mechanum.putc(64); |
nodoame | 4:bae4e2d103d4 | 156 | btFlag=true; |
nodoame | 20:373fa71ce05b | 157 | Blue=0;Green=0.8;Red=0; |
nodoame | 15:c941d06092ec | 158 | vector=scVector; |
nodoame | 14:aaf2ae25e508 | 159 | } |
nodoame | 11:1ca2498815c9 | 160 | |
nodoame | 15:c941d06092ec | 161 | //片方のレーザーが反応したとき |
nodoame | 20:373fa71ce05b | 162 | if(btFlag&&!laser){ |
nodoame | 20:373fa71ce05b | 163 | if(!(((int)DATA[1]&2)==2)){ |
nodoame | 15:c941d06092ec | 164 | laser=1; |
nodoame | 20:373fa71ce05b | 165 | Red=0.8; |
nodoame | 15:c941d06092ec | 166 | vector=0; |
nodoame | 15:c941d06092ec | 167 | } |
nodoame | 20:373fa71ce05b | 168 | else if(!(((int)DATA[1]&1)==1)){ |
nodoame | 15:c941d06092ec | 169 | laser=2; |
nodoame | 20:373fa71ce05b | 170 | Red=0.8; |
nodoame | 15:c941d06092ec | 171 | vector=0; |
nodoame | 9:489a085d1703 | 172 | } |
nodoame | 9:489a085d1703 | 173 | } |
nodoame | 15:c941d06092ec | 174 | |
nodoame | 15:c941d06092ec | 175 | //もう片方のレーザーが反応した時 |
nodoame | 20:373fa71ce05b | 176 | else if(!(((int)DATA[1]&laser)==laser)&&laser&&!stopFlag){ |
nodoame | 20:373fa71ce05b | 177 | Green=0;Red=0.8;Blue=0.8; |
nodoame | 20:373fa71ce05b | 178 | vector=64; |
nodoame | 20:373fa71ce05b | 179 | stopFlag=true; |
nodoame | 20:373fa71ce05b | 180 | wait(0.05); |
nodoame | 20:373fa71ce05b | 181 | } |
nodoame | 20:373fa71ce05b | 182 | //ストップ後 |
nodoame | 20:373fa71ce05b | 183 | else if(stopFlag) |
nodoame | 20:373fa71ce05b | 184 | { |
nodoame | 20:373fa71ce05b | 185 | vector=162; |
nodoame | 20:373fa71ce05b | 186 | breakFlag=true; |
nodoame | 0:dc587be179e9 | 187 | } |
nodoame | 4:bae4e2d103d4 | 188 | |
nodoame | 15:c941d06092ec | 189 | //pc.printf("%d\r\n",DATA[1]); |
nodoame | 20:373fa71ce05b | 190 | //deg=devidePoint((double)DATA[3],(double)DATA[2],15,360/devideNum); |
nodoame | 20:373fa71ce05b | 191 | //pc.printf("%d\r\n",scVector); |
nodoame | 0:dc587be179e9 | 192 | Mechanum.putc(vector); |
nodoame | 20:373fa71ce05b | 193 | wait(0.0126f); |
nodoame | 0:dc587be179e9 | 194 | } |
nodoame | 4:bae4e2d103d4 | 195 | btFlag=false; |
nodoame | 5:428b7ac86810 | 196 | Blue=0;Green=0;Red=0; |
nodoame | 0:dc587be179e9 | 197 | } |
nodoame | 0:dc587be179e9 | 198 | |
nodoame | 0:dc587be179e9 | 199 | |
nodoame | 5:428b7ac86810 | 200 | bool shotToDenziben(char reg, char data ,int size,int addr) |
nodoame | 0:dc587be179e9 | 201 | { |
nodoame | 5:428b7ac86810 | 202 | char REG[2] = {reg,size}; |
nodoame | 5:428b7ac86810 | 203 | char DATA[2]={data,0}; |
nodoame | 5:428b7ac86810 | 204 | bool A = i2c.write(addr,REG,2); |
nodoame | 5:428b7ac86810 | 205 | A|= i2c.write(addr,DATA,size); |
nodoame | 1:a3bfd422ea9e | 206 | return A; |
nodoame | 0:dc587be179e9 | 207 | } |
nodoame | 0:dc587be179e9 | 208 | |
nodoame | 5:428b7ac86810 | 209 | char getshot(char reg) |
nodoame | 5:428b7ac86810 | 210 | { |
nodoame | 5:428b7ac86810 | 211 | char input=0; |
nodoame | 5:428b7ac86810 | 212 | char DATA[2] = {reg,1}; |
nodoame | 5:428b7ac86810 | 213 | i2c.write(airAddr,DATA,2); |
nodoame | 5:428b7ac86810 | 214 | wait(0.005f); |
nodoame | 5:428b7ac86810 | 215 | i2c.read(airAddr,&input,1); |
nodoame | 5:428b7ac86810 | 216 | return input; |
nodoame | 5:428b7ac86810 | 217 | } |
nodoame | 5:428b7ac86810 | 218 | |
nodoame | 12:6445a3c3d34c | 219 | void setFCLED(double RED,double GREEN,double BLUE) |
nodoame | 12:6445a3c3d34c | 220 | { |
nodoame | 12:6445a3c3d34c | 221 | Red=RED; |
nodoame | 12:6445a3c3d34c | 222 | Green=GREEN; |
nodoame | 12:6445a3c3d34c | 223 | Blue=BLUE; |
nodoame | 12:6445a3c3d34c | 224 | } |
nodoame | 12:6445a3c3d34c | 225 | |
nodoame | 4:bae4e2d103d4 | 226 | int main() { |
nodoame | 0:dc587be179e9 | 227 | pc.baud(230400); |
nodoame | 24:ee0943b12feb | 228 | Dev.baud(921600);//PS3 |
nodoame | 24:ee0943b12feb | 229 | //Dev.baud(115200);//XBOX |
nodoame | 0:dc587be179e9 | 230 | Mechanum.baud(230400); |
nodoame | 5:428b7ac86810 | 231 | DigitalIn bt(USER_BUTTON); |
nodoame | 0:dc587be179e9 | 232 | Dev.attach(num,Serial::RxIrq);//受信割り込み設定 |
nodoame | 1:a3bfd422ea9e | 233 | Green=0;Blue=0;Red=0; |
nodoame | 12:6445a3c3d34c | 234 | double gValue=0,bValue=0,rValue=0; |
nodoame | 3:c290afbacd1c | 235 | DigitalOut l(PB_2); |
nodoame | 3:c290afbacd1c | 236 | int sqf=0; |
nodoame | 20:373fa71ce05b | 237 | double deg=32; |
nodoame | 0:dc587be179e9 | 238 | int val; |
nodoame | 1:a3bfd422ea9e | 239 | i2c.frequency(400000); |
nodoame | 12:6445a3c3d34c | 240 | setFCLED(0,0.8,0.8); |
nodoame | 23:d5f7e3dab589 | 241 | bool obonFlag=false,pLeftF=false,pRightF=false,btCrF=false,detFinF=false,touchSF=false; |
nodoame | 0:dc587be179e9 | 242 | |
nodoame | 0:dc587be179e9 | 243 | while(true) |
nodoame | 12:6445a3c3d34c | 244 | { |
nodoame | 23:d5f7e3dab589 | 245 | /* //ポール検出モード |
nodoame | 0:dc587be179e9 | 246 | if(getBt(btTri)&&getBt(btSph)){ |
nodoame | 20:373fa71ce05b | 247 | if(deg>devideNum-1); |
nodoame | 20:373fa71ce05b | 248 | else if(deg<17){ |
nodoame | 20:373fa71ce05b | 249 | //pc.printf("R\r\n"); |
nodoame | 20:373fa71ce05b | 250 | detFinF=detectPole(TNR); |
nodoame | 20:373fa71ce05b | 251 | } |
nodoame | 20:373fa71ce05b | 252 | else{ |
nodoame | 20:373fa71ce05b | 253 | //pc.printf("L\r\n"); |
nodoame | 20:373fa71ce05b | 254 | detFinF=detectPole(TNL); |
nodoame | 20:373fa71ce05b | 255 | } |
nodoame | 23:d5f7e3dab589 | 256 | }*/ |
nodoame | 5:428b7ac86810 | 257 | |
nodoame | 23:d5f7e3dab589 | 258 | do{ |
nodoame | 23:d5f7e3dab589 | 259 | bool l=getBt(btL),r=getBt(btR),t=getBt(btTri); |
nodoame | 23:d5f7e3dab589 | 260 | if(!l&&!r&&!t) |
nodoame | 23:d5f7e3dab589 | 261 | pushF=false; |
nodoame | 23:d5f7e3dab589 | 262 | if(pushF||!obonFlag) |
nodoame | 23:d5f7e3dab589 | 263 | break; |
nodoame | 23:d5f7e3dab589 | 264 | |
nodoame | 23:d5f7e3dab589 | 265 | //射出 |
nodoame | 23:d5f7e3dab589 | 266 | if(l){ |
nodoame | 24:ee0943b12feb | 267 | //pc.printf("L\r\n"); |
nodoame | 23:d5f7e3dab589 | 268 | pushF=true; |
nodoame | 23:d5f7e3dab589 | 269 | kRed=shotToDenziben(airReg,1,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 270 | wait(shotWait); |
nodoame | 23:d5f7e3dab589 | 271 | kRed=shotToDenziben(airReg,0,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 272 | kRed=0; |
nodoame | 23:d5f7e3dab589 | 273 | } |
nodoame | 23:d5f7e3dab589 | 274 | |
nodoame | 23:d5f7e3dab589 | 275 | //射出 |
nodoame | 23:d5f7e3dab589 | 276 | else if(r){ |
nodoame | 24:ee0943b12feb | 277 | //pc.printf("R\r\n"); |
nodoame | 23:d5f7e3dab589 | 278 | pushF=true; |
nodoame | 23:d5f7e3dab589 | 279 | kRed=shotToDenziben(airReg,2,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 280 | wait(shotWait); |
nodoame | 23:d5f7e3dab589 | 281 | kRed=shotToDenziben(airReg,0,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 282 | //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2)); |
nodoame | 23:d5f7e3dab589 | 283 | //i2c.write(airAddr,cmd,2); |
nodoame | 23:d5f7e3dab589 | 284 | kRed=0; |
nodoame | 23:d5f7e3dab589 | 285 | } |
nodoame | 23:d5f7e3dab589 | 286 | |
nodoame | 23:d5f7e3dab589 | 287 | //射出 |
nodoame | 23:d5f7e3dab589 | 288 | else if(t){ |
nodoame | 24:ee0943b12feb | 289 | //pc.printf("T\r\n"); |
nodoame | 23:d5f7e3dab589 | 290 | pushF=true; |
nodoame | 23:d5f7e3dab589 | 291 | kRed=shotToDenziben(airReg,4,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 292 | wait(shotWait); |
nodoame | 23:d5f7e3dab589 | 293 | kRed=shotToDenziben(airReg,0,1,airAddr); |
nodoame | 23:d5f7e3dab589 | 294 | kRed=0; |
nodoame | 23:d5f7e3dab589 | 295 | } |
nodoame | 23:d5f7e3dab589 | 296 | |
nodoame | 23:d5f7e3dab589 | 297 | }while(false); |
nodoame | 3:c290afbacd1c | 298 | |
nodoame | 5:428b7ac86810 | 299 | //レーザーポインタ |
nodoame | 3:c290afbacd1c | 300 | if(getBt(btSqa)&&sqf){ |
nodoame | 3:c290afbacd1c | 301 | sqf=0; |
nodoame | 3:c290afbacd1c | 302 | l=!l; |
nodoame | 4:bae4e2d103d4 | 303 | kBlue=!kBlue; |
nodoame | 0:dc587be179e9 | 304 | } |
nodoame | 3:c290afbacd1c | 305 | else if(!getBt(btSqa)) |
nodoame | 3:c290afbacd1c | 306 | sqf=1; |
nodoame | 3:c290afbacd1c | 307 | |
nodoame | 22:ab619079fb8d | 308 | //タッチセンサ |
nodoame | 23:d5f7e3dab589 | 309 | if(((int)DATA[1]&12)==12&&!touchSF){ |
nodoame | 23:d5f7e3dab589 | 310 | touchSF=true; |
nodoame | 24:ee0943b12feb | 311 | gValue=0.5; |
nodoame | 20:373fa71ce05b | 312 | } |
nodoame | 24:ee0943b12feb | 313 | else if(!(((int)DATA[1]&12)==12)){ |
nodoame | 23:d5f7e3dab589 | 314 | touchSF=false; |
nodoame | 24:ee0943b12feb | 315 | gValue=0; |
nodoame | 23:d5f7e3dab589 | 316 | } |
nodoame | 20:373fa71ce05b | 317 | //お盆回し |
nodoame | 20:373fa71ce05b | 318 | if(getPress(presUp)){ |
nodoame | 24:ee0943b12feb | 319 | //pc.printf("L\r\n"); |
nodoame | 20:373fa71ce05b | 320 | obonFlag=true; |
nodoame | 22:ab619079fb8d | 321 | Mechanum.putc(162); |
nodoame | 24:ee0943b12feb | 322 | rValue=0.5; |
nodoame | 20:373fa71ce05b | 323 | kRed=0; |
nodoame | 22:ab619079fb8d | 324 | wait(0.2); |
nodoame | 20:373fa71ce05b | 325 | } |
nodoame | 20:373fa71ce05b | 326 | else if(getPress(presDown)){ |
nodoame | 22:ab619079fb8d | 327 | Mechanum.putc(163); |
nodoame | 23:d5f7e3dab589 | 328 | rValue=0; |
nodoame | 20:373fa71ce05b | 329 | obonFlag=false; |
nodoame | 20:373fa71ce05b | 330 | kRed=0; |
nodoame | 22:ab619079fb8d | 331 | wait(0.2); |
nodoame | 22:ab619079fb8d | 332 | } |
nodoame | 19:cd036cc40a2d | 333 | |
nodoame | 20:373fa71ce05b | 334 | deg=devidePoint((double)DATA[3],(double)DATA[2],15,360/devideNum); |
nodoame | 23:d5f7e3dab589 | 335 | |
nodoame | 20:373fa71ce05b | 336 | if(getPress(btSel)||(detFinF&°!=devideNum)){ |
nodoame | 20:373fa71ce05b | 337 | detFinF=false; |
nodoame | 20:373fa71ce05b | 338 | Mechanum.putc(163); |
nodoame | 20:373fa71ce05b | 339 | wait(0.1); |
nodoame | 19:cd036cc40a2d | 340 | } |
nodoame | 20:373fa71ce05b | 341 | else { |
nodoame | 20:373fa71ce05b | 342 | val=valueForMechanum(deg,devideNum,getBt(trigL),getBt(trigR),getBt(btSph)); |
nodoame | 20:373fa71ce05b | 343 | //pc.printf("%lf\r\n",deg); |
nodoame | 19:cd036cc40a2d | 344 | } |
nodoame | 20:373fa71ce05b | 345 | |
nodoame | 11:1ca2498815c9 | 346 | |
nodoame | 11:1ca2498815c9 | 347 | //一定時間通信してないと停止 |
nodoame | 11:1ca2498815c9 | 348 | if(stopCounter>stopCount) |
nodoame | 11:1ca2498815c9 | 349 | val=64; |
nodoame | 11:1ca2498815c9 | 350 | else |
nodoame | 11:1ca2498815c9 | 351 | stopCounter++; |
nodoame | 0:dc587be179e9 | 352 | Mechanum.putc(val); |
nodoame | 24:ee0943b12feb | 353 | //bValue=0.8; |
nodoame | 12:6445a3c3d34c | 354 | setFCLED(rValue,gValue,bValue); |
nodoame | 0:dc587be179e9 | 355 | wait(0.03f); |
nodoame | 11:1ca2498815c9 | 356 | do{ |
nodoame | 11:1ca2498815c9 | 357 | if(!debugFlag) |
nodoame | 11:1ca2498815c9 | 358 | break; |
nodoame | 20:373fa71ce05b | 359 | //pc.printf("%d\r\n",DATA[6]); |
nodoame | 20:373fa71ce05b | 360 | //if(getPress(btSel)) |
nodoame | 20:373fa71ce05b | 361 | // pc.printf("up\r\n"); |
nodoame | 24:ee0943b12feb | 362 | pc.printf("val:%d\r\n",val); |
nodoame | 24:ee0943b12feb | 363 | pc.printf("a"); |
nodoame | 11:1ca2498815c9 | 364 | //printf("%lf:%d:%d\r\n",deg,(int)DATA[3],(int)DATA[2]); |
nodoame | 11:1ca2498815c9 | 365 | //printf("%d\r\n",(int)DATA[0]); |
nodoame | 11:1ca2498815c9 | 366 | //pc.printf("DATA[1]%d\r\n",(int)(DATA[1]&0x02)); |
nodoame | 11:1ca2498815c9 | 367 | //printf("deg:%lfX1:%d:bt%ddeg:%lfval:%d\r\n",deg,(int)DATA[1],getBt(btSqa),deg,val); |
nodoame | 20:373fa71ce05b | 368 | //pc.printf("%lf\r\n",deg); |
nodoame | 11:1ca2498815c9 | 369 | }while(false); |
nodoame | 0:dc587be179e9 | 370 | } |
nodoame | 0:dc587be179e9 | 371 | } |