NHK2019ROBOCON team A manual robot program 10/4 version (ロボコン当日使用プログラム)

Dependencies:   mbed 2019ROBOKONmanualProgram

Committer:
shina
Date:
Fri Sep 27 23:53:04 2019 +0000
Revision:
3:82008ebeb93c
Parent:
2:830db42bae7e
Child:
4:ab73021bbce1
NHK2019robocon manual program 9/28 version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shina 0:c7e17c2fd542 1 /////////////////////////////////////
shina 0:c7e17c2fd542 2 /*NHK2019*/
shina 1:99294241f2ba 3 //Aチーム手動機プログラム
shina 0:c7e17c2fd542 4 /*
shina 0:c7e17c2fd542 5 アドレス
shina 0:c7e17c2fd542 6 0x10:右前
shina 1:99294241f2ba 7 0x12:左後ろ
shina 0:c7e17c2fd542 8 0x14:右後ろ
shina 1:99294241f2ba 9 0x16:左前
shina 0:c7e17c2fd542 10 0x18:サーボ制御回路
shina 0:c7e17c2fd542 11 0x20:右ラック
shina 2:830db42bae7e 12 0x22:左ラック.
shina 0:c7e17c2fd542 13 0x24:回収機構
shina 0:c7e17c2fd542 14 0x26:右ファン
shina 0:c7e17c2fd542 15 0x28:左ファン
shina 1:99294241f2ba 16 0x30:吐き出し機構
shina 0:c7e17c2fd542 17 */
shina 0:c7e17c2fd542 18 /////////////////////////////////////
shina 0:c7e17c2fd542 19
shina 0:c7e17c2fd542 20 //宣言
shina 0:c7e17c2fd542 21 #include "mbed.h"
shina 0:c7e17c2fd542 22 #include "PS3.h"
shina 0:c7e17c2fd542 23 I2C i2c(D14,D15);
shina 0:c7e17c2fd542 24 Serial pc(USBTX,USBRX);
shina 0:c7e17c2fd542 25 Serial slave(PC_6,PC_7);
shina 0:c7e17c2fd542 26 PS3 ps3(D8,D2);
shina 0:c7e17c2fd542 27 DigitalOut led(D5);//電源確認
shina 0:c7e17c2fd542 28 DigitalOut tsushin(D6);//通信確認
shina 0:c7e17c2fd542 29 DigitalOut data_check(D7);
shina 0:c7e17c2fd542 30 DigitalOut pwm(D4);
shina 0:c7e17c2fd542 31 DigitalOut stop(D10);
shina 0:c7e17c2fd542 32 DigitalOut led1(LED1);
shina 2:830db42bae7e 33 Timer timer;
shina 2:830db42bae7e 34 Timer timer2;
shina 1:99294241f2ba 35
shina 0:c7e17c2fd542 36 //変数
shina 0:c7e17c2fd542 37 char data1;//右上
shina 0:c7e17c2fd542 38 char data2;//左上
shina 0:c7e17c2fd542 39 char data3;//右下
shina 0:c7e17c2fd542 40 char data4;//左下
shina 0:c7e17c2fd542 41 char data_servo;
shina 0:c7e17c2fd542 42 char data5;//ラック直動右
shina 0:c7e17c2fd542 43 char data6;//ラック直動左
shina 0:c7e17c2fd542 44 char data7;//回収機構
shina 0:c7e17c2fd542 45 char data8;//右ファン
shina 0:c7e17c2fd542 46 char data9;//左ファン
shina 1:99294241f2ba 47 char data10;//パトランプ
shina 1:99294241f2ba 48 char data11;//吐き出し機構
shina 2:830db42bae7e 49 char get_data_rs232=0x00;
shina 0:c7e17c2fd542 50 int Ry;
shina 0:c7e17c2fd542 51 int Rx;
shina 1:99294241f2ba 52 int Ly;
shina 0:c7e17c2fd542 53 int right1;
shina 1:99294241f2ba 54 int right2;
shina 0:c7e17c2fd542 55 int left1;
shina 0:c7e17c2fd542 56 int left2;
shina 0:c7e17c2fd542 57 int select;
shina 0:c7e17c2fd542 58 int start;
shina 0:c7e17c2fd542 59 int circle;
shina 0:c7e17c2fd542 60 int cross;
shina 1:99294241f2ba 61 int triangle;
shina 1:99294241f2ba 62 int square;
shina 0:c7e17c2fd542 63 int ue1;
shina 0:c7e17c2fd542 64 int shita;
shina 0:c7e17c2fd542 65 int migi1;
shina 0:c7e17c2fd542 66 int hidari1;
shina 0:c7e17c2fd542 67 int tushin_check;
shina 0:c7e17c2fd542 68 int old_select=0;
shina 0:c7e17c2fd542 69 int i=1;
shina 0:c7e17c2fd542 70 int old_start=0;
shina 0:c7e17c2fd542 71 int j=1;
shina 0:c7e17c2fd542 72 int old_circle=0;
shina 0:c7e17c2fd542 73 int k=1;
shina 1:99294241f2ba 74 int old_square=0;
shina 1:99294241f2ba 75 int old_migi1=0;
shina 1:99294241f2ba 76 int old_hidari1=0;
shina 1:99294241f2ba 77 int n=1;
shina 1:99294241f2ba 78 int old_right2=0;
shina 1:99294241f2ba 79 int o=1;
shina 1:99294241f2ba 80 int old_right1=0;
shina 1:99294241f2ba 81 int old_left1=0;
shina 2:830db42bae7e 82 int p=5;
shina 1:99294241f2ba 83 int q=0;
shina 2:830db42bae7e 84 int old_ue1=0;
shina 2:830db42bae7e 85 int old_shita=0;
shina 2:830db42bae7e 86 int old_left2=0;
shina 2:830db42bae7e 87 int old_triangle=0;
shina 2:830db42bae7e 88 int old_cross=0;
shina 2:830db42bae7e 89 int r=6;
shina 2:830db42bae7e 90 int s=5;
shina 0:c7e17c2fd542 91
shina 0:c7e17c2fd542 92
shina 0:c7e17c2fd542 93 //関数プロトタイプ宣言
shina 1:99294241f2ba 94 void initialization();
shina 0:c7e17c2fd542 95 void get_data();
shina 0:c7e17c2fd542 96 void change_data();
shina 0:c7e17c2fd542 97 void change_pwm();
shina 0:c7e17c2fd542 98 void change_servo();
shina 2:830db42bae7e 99 //void change_rack();
shina 0:c7e17c2fd542 100 void change_fan();
shina 0:c7e17c2fd542 101 void send_data(char address,char data);
shina 0:c7e17c2fd542 102 void emergency();
shina 1:99294241f2ba 103 void change_rack_2();
shina 3:82008ebeb93c 104 void sequence_kaisyu();
shina 3:82008ebeb93c 105 //void kaisyu();
shina 3:82008ebeb93c 106 //void sequence_kaisyu_short();
shina 2:830db42bae7e 107 //void sequence_hakidashi();
shina 2:830db42bae7e 108 void hakidashi();
shina 2:830db42bae7e 109 void mode_change();
shina 1:99294241f2ba 110
shina 1:99294241f2ba 111
shina 0:c7e17c2fd542 112
shina 0:c7e17c2fd542 113 //メイン関数
shina 2:830db42bae7e 114 int main()
shina 2:830db42bae7e 115 {
shina 0:c7e17c2fd542 116 led=1;
shina 2:830db42bae7e 117 pwm=1;
shina 1:99294241f2ba 118 initialization();
shina 2:830db42bae7e 119 while(true) {
shina 0:c7e17c2fd542 120 emergency();
shina 0:c7e17c2fd542 121 get_data();
shina 2:830db42bae7e 122 mode_change();
shina 0:c7e17c2fd542 123 change_pwm();
shina 0:c7e17c2fd542 124 change_servo();
shina 0:c7e17c2fd542 125 change_data();
shina 2:830db42bae7e 126 //change_rack();
shina 1:99294241f2ba 127 change_rack_2();
shina 3:82008ebeb93c 128 sequence_kaisyu();
shina 3:82008ebeb93c 129 //kaisyu();
shina 3:82008ebeb93c 130 //sequence_kaisyu_short();
shina 2:830db42bae7e 131 //sequence_hakidashi();
shina 2:830db42bae7e 132 hakidashi();
shina 0:c7e17c2fd542 133 change_fan();
shina 0:c7e17c2fd542 134 send_data(0x10,data1);
shina 0:c7e17c2fd542 135 send_data(0x12,data2);
shina 0:c7e17c2fd542 136 send_data(0x14,data3);
shina 0:c7e17c2fd542 137 send_data(0x16,data4);
shina 0:c7e17c2fd542 138 send_data(0x18,data_servo);
shina 0:c7e17c2fd542 139 send_data(0x20,data5);
shina 0:c7e17c2fd542 140 send_data(0x22,data6);
shina 1:99294241f2ba 141 //send_data(0x24,data7);
shina 0:c7e17c2fd542 142 send_data(0x26,data8);
shina 0:c7e17c2fd542 143 send_data(0x28,data9);
shina 1:99294241f2ba 144 send_data(0x40,data10);
shina 1:99294241f2ba 145 //send_data(0x30,data11);
shina 2:830db42bae7e 146
shina 2:830db42bae7e 147
shina 2:830db42bae7e 148
shina 1:99294241f2ba 149
shina 0:c7e17c2fd542 150 }
shina 2:830db42bae7e 151 }
shina 2:830db42bae7e 152
shina 2:830db42bae7e 153
shina 1:99294241f2ba 154 //初期化
shina 2:830db42bae7e 155 void initialization()
shina 2:830db42bae7e 156 {
shina 1:99294241f2ba 157 data1=0x80;
shina 1:99294241f2ba 158 data2=0x80;
shina 1:99294241f2ba 159 data3=0x80;
shina 1:99294241f2ba 160 data4=0x80;
shina 1:99294241f2ba 161 data5=0x80;
shina 1:99294241f2ba 162 data6=0x80;
shina 1:99294241f2ba 163 data7=0x10;
shina 1:99294241f2ba 164 data8=0x80;
shina 1:99294241f2ba 165 data9=0x80;
shina 1:99294241f2ba 166 data10=0x80;
shina 1:99294241f2ba 167 data11=0x80;
shina 2:830db42bae7e 168
shina 1:99294241f2ba 169 send_data(0x10,data1);
shina 1:99294241f2ba 170 send_data(0x12,data2);
shina 1:99294241f2ba 171 send_data(0x14,data3);
shina 1:99294241f2ba 172 send_data(0x16,data4);
shina 1:99294241f2ba 173 send_data(0x20,data5);
shina 1:99294241f2ba 174 send_data(0x22,data6);
shina 1:99294241f2ba 175 send_data(0x24,data7);
shina 1:99294241f2ba 176 send_data(0x26,data8);
shina 1:99294241f2ba 177 send_data(0x28,data9);
shina 1:99294241f2ba 178 send_data(0x40,data10);
shina 1:99294241f2ba 179 send_data(0x30,data11);
shina 1:99294241f2ba 180
shina 1:99294241f2ba 181
shina 2:830db42bae7e 182 data10=0x3f;
shina 2:830db42bae7e 183 send_data(0x40,data10);
shina 1:99294241f2ba 184
shina 2:830db42bae7e 185 if(q==0){
shina 2:830db42bae7e 186 data10=0xdf;
shina 2:830db42bae7e 187 send_data(0x40,data10);
shina 2:830db42bae7e 188 }else if(q==1){
shina 2:830db42bae7e 189 data10=0xcf;
shina 2:830db42bae7e 190 send_data(0x40,data10);
shina 2:830db42bae7e 191 }
shina 2:830db42bae7e 192
shina 3:82008ebeb93c 193 /*data_servo=0x03;
shina 3:82008ebeb93c 194 send_data(0x18,data_servo);
shina 3:82008ebeb93c 195 data_servo=0x04;
shina 3:82008ebeb93c 196 send_data(0x18,data_servo);*/
shina 3:82008ebeb93c 197 timer2.reset();
shina 2:830db42bae7e 198
shina 2:830db42bae7e 199 }
shina 2:830db42bae7e 200
shina 2:830db42bae7e 201
shina 0:c7e17c2fd542 202 //データ読み込み
shina 2:830db42bae7e 203 void get_data()
shina 2:830db42bae7e 204 {
shina 0:c7e17c2fd542 205 Ry=ps3.getRightJoystickYaxis();
shina 0:c7e17c2fd542 206 Rx=ps3.getRightJoystickXaxis();
shina 1:99294241f2ba 207 Ly=ps3.getLeftJoystickYaxis();
shina 0:c7e17c2fd542 208 circle=ps3.getButtonState(maru);
shina 0:c7e17c2fd542 209 cross=ps3.getButtonState(batu);
shina 1:99294241f2ba 210 triangle=ps3.getButtonState(sankaku);
shina 1:99294241f2ba 211 square=ps3.getButtonState(sikaku);
shina 0:c7e17c2fd542 212 left1=ps3.getButtonState(L1);
shina 0:c7e17c2fd542 213 left2=ps3.getButtonState(L2);
shina 0:c7e17c2fd542 214 right1=ps3.getButtonState(R1);
shina 1:99294241f2ba 215 right2=ps3.getButtonState(R2);
shina 0:c7e17c2fd542 216 select=ps3.getSELECTState();
shina 0:c7e17c2fd542 217 start=ps3.getSTARTState();
shina 0:c7e17c2fd542 218 ue1=ps3.getButtonState(ue);
shina 0:c7e17c2fd542 219 shita=ps3.getButtonState(sita);
shina 0:c7e17c2fd542 220 hidari1=ps3.getButtonState(hidari);
shina 0:c7e17c2fd542 221 migi1=ps3.getButtonState(migi);
shina 1:99294241f2ba 222 get_data_rs232=slave.getc();
shina 3:82008ebeb93c 223
shina 2:830db42bae7e 224
shina 1:99294241f2ba 225
shina 2:830db42bae7e 226 if(get_data_rs232) {
shina 1:99294241f2ba 227 led1=1;
shina 2:830db42bae7e 228 } else {
shina 2:830db42bae7e 229 led1=0;
shina 2:830db42bae7e 230 }
shina 2:830db42bae7e 231 //pc.printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",Ry,Rx,Ly,left1,left2,right1,right2,select,start,ue1,shita,triangle,square,migi1,hidari1,tushin_check,i);
shina 2:830db42bae7e 232 if(Ry==0&&Rx==0&&Ly==0&&left1==0&&right1==0&&right2==0&&left2==0&&select==0&&start==0&&shita==0&&triangle==0&&ue1==0&&migi1==0&&hidari1==0&&square==0&&circle==0&&cross==0) {
shina 0:c7e17c2fd542 233 data_check=0;
shina 2:830db42bae7e 234 } else {
shina 2:830db42bae7e 235 data_check=1;
shina 0:c7e17c2fd542 236 }
shina 2:830db42bae7e 237
shina 2:830db42bae7e 238 }
shina 2:830db42bae7e 239
shina 0:c7e17c2fd542 240 //緊急停止
shina 2:830db42bae7e 241 void emergency()
shina 2:830db42bae7e 242 {
shina 2:830db42bae7e 243 if(start!=old_start) {
shina 2:830db42bae7e 244 old_start=start;
shina 2:830db42bae7e 245 if(start==1) {
shina 2:830db42bae7e 246 if(j==1) {
shina 2:830db42bae7e 247 //緊急停止
shina 2:830db42bae7e 248 led=0;
shina 2:830db42bae7e 249 stop=1;
shina 2:830db42bae7e 250 j=0;
shina 2:830db42bae7e 251 } else if(j==0) {
shina 2:830db42bae7e 252 //緊急停止解除
shina 2:830db42bae7e 253 led=1;
shina 2:830db42bae7e 254 stop=0;
shina 2:830db42bae7e 255 j=1;
shina 0:c7e17c2fd542 256 }
shina 0:c7e17c2fd542 257 }
shina 2:830db42bae7e 258 }
shina 2:830db42bae7e 259 }
shina 2:830db42bae7e 260
shina 2:830db42bae7e 261
shina 2:830db42bae7e 262 //モードチェンジ
shina 2:830db42bae7e 263 void mode_change(){
shina 2:830db42bae7e 264 if(old_select!=select){
shina 2:830db42bae7e 265 old_select=select;
shina 2:830db42bae7e 266 if(select==1){
shina 2:830db42bae7e 267 if(q==0){
shina 2:830db42bae7e 268 //送風モード
shina 2:830db42bae7e 269 q=1;
shina 3:82008ebeb93c 270 /* data_servo=0x03;
shina 3:82008ebeb93c 271 send_data(0x18,data_servo);
shina 3:82008ebeb93c 272 data_servo=0x04;
shina 3:82008ebeb93c 273 send_data(0x18,data_servo);*/
shina 2:830db42bae7e 274 data10=0xcf;
shina 2:830db42bae7e 275 send_data(0x40,data10);
shina 2:830db42bae7e 276 }else if(q==1){
shina 2:830db42bae7e 277 //回収モード
shina 2:830db42bae7e 278 q=0;
shina 2:830db42bae7e 279 data10=0xdf;
shina 2:830db42bae7e 280 send_data(0x40,data10);
shina 2:830db42bae7e 281 }
shina 2:830db42bae7e 282 }
shina 2:830db42bae7e 283 }
shina 0:c7e17c2fd542 284 }
shina 0:c7e17c2fd542 285
shina 0:c7e17c2fd542 286 //データ変化(メカナム)
shina 2:830db42bae7e 287 void change_data()
shina 2:830db42bae7e 288 {
shina 2:830db42bae7e 289
shina 2:830db42bae7e 290 if(Ry!=0||Rx!=0) {
shina 1:99294241f2ba 291 square=0;
shina 2:830db42bae7e 292 migi1=0;
shina 2:830db42bae7e 293 }
shina 2:830db42bae7e 294
shina 2:830db42bae7e 295 if(Ry>30&&i==0) {
shina 2:830db42bae7e 296 if(right1==1) {
shina 2:830db42bae7e 297 data1=0xcf;
shina 2:830db42bae7e 298 data2=0x00;
shina 2:830db42bae7e 299 data3=0xcf;
shina 2:830db42bae7e 300 data4=0x00;
shina 2:830db42bae7e 301 } else if(left1==1) {
shina 2:830db42bae7e 302 data1=0x00;
shina 2:830db42bae7e 303 data2=0xcf;
shina 2:830db42bae7e 304 data3=0x00;
shina 2:830db42bae7e 305 data4=0xcf;
shina 2:830db42bae7e 306 } else {
shina 2:830db42bae7e 307 data1=0x00;
shina 2:830db42bae7e 308 data2=0x00;
shina 2:830db42bae7e 309 data3=0x00;
shina 2:830db42bae7e 310 data4=0x00;
shina 1:99294241f2ba 311 }
shina 2:830db42bae7e 312 } else if(Ry<-30&&i==0) {
shina 1:99294241f2ba 313 if(right1==1){
shina 2:830db42bae7e 314 data1=0xdf;
shina 2:830db42bae7e 315 data2=0xff;
shina 2:830db42bae7e 316 data3=0xdf;
shina 2:830db42bae7e 317 data4=0xff;
shina 1:99294241f2ba 318 }else if(left1==1){
shina 1:99294241f2ba 319 data1=0xff;
shina 1:99294241f2ba 320 data2=0xdf;
shina 1:99294241f2ba 321 data3=0xff;
shina 1:99294241f2ba 322 data4=0xdf;
shina 2:830db42bae7e 323 }else{
shina 2:830db42bae7e 324 data1=0xff;
shina 2:830db42bae7e 325 data2=0xff;
shina 2:830db42bae7e 326 data3=0xff;
shina 1:99294241f2ba 327 data4=0xff;
shina 2:830db42bae7e 328 }
shina 2:830db42bae7e 329 } else if(Rx>30&&i==0) {
shina 2:830db42bae7e 330 if(right1==1) {
shina 2:830db42bae7e 331 data1=0xff;
shina 2:830db42bae7e 332 data2=0xdf;
shina 2:830db42bae7e 333 data3=0xcf;
shina 2:830db42bae7e 334 data4=0x00;
shina 2:830db42bae7e 335 } else if(left1==1) {
shina 2:830db42bae7e 336 data1=0xdf;
shina 2:830db42bae7e 337 data2=0xff;
shina 2:830db42bae7e 338 data3=0x00;
shina 2:830db42bae7e 339 data4=0xcf;
shina 2:830db42bae7e 340 } else {
shina 2:830db42bae7e 341 data1=0xff;
shina 2:830db42bae7e 342 data2=0xff;
shina 2:830db42bae7e 343 data3=0x00;
shina 2:830db42bae7e 344 data4=0x00;
shina 1:99294241f2ba 345 }
shina 2:830db42bae7e 346 } else if(Rx<-30&&i==0) {
shina 2:830db42bae7e 347 if(right1==1) {
shina 2:830db42bae7e 348 data1=0xcf;
shina 2:830db42bae7e 349 data2=0x00;
shina 2:830db42bae7e 350 data3=0xff;
shina 2:830db42bae7e 351 data4=0xdf;
shina 2:830db42bae7e 352 } else if(left1==1) {
shina 2:830db42bae7e 353 data1=0x00;
shina 2:830db42bae7e 354 data2=0xcf;
shina 2:830db42bae7e 355 data3=0xdf;
shina 2:830db42bae7e 356 data4=0xff;
shina 2:830db42bae7e 357 } else {
shina 2:830db42bae7e 358 data1=0x00;
shina 2:830db42bae7e 359 data2=0x00;
shina 2:830db42bae7e 360 data3=0xff;
shina 2:830db42bae7e 361 data4=0xff;
shina 2:830db42bae7e 362 }
shina 2:830db42bae7e 363 } else if(right1==1&&i==0) {
shina 1:99294241f2ba 364 data1=0xff;
shina 1:99294241f2ba 365 data2=0x00;
shina 1:99294241f2ba 366 data3=0xff;
shina 1:99294241f2ba 367 data4=0x00;
shina 2:830db42bae7e 368 } else if(left1==1&&i==0) {
shina 1:99294241f2ba 369 data1=0x00;
shina 1:99294241f2ba 370 data2=0xff;
shina 1:99294241f2ba 371 data3=0x00;
shina 1:99294241f2ba 372 data4=0xff;
shina 2:830db42bae7e 373 } else if(Ry>30&&i==1) {
shina 2:830db42bae7e 374 if(right1==1) {
shina 2:830db42bae7e 375 data1=0x4f;
shina 2:830db42bae7e 376 data2=0x3f;
shina 2:830db42bae7e 377 data3=0x4f;
shina 2:830db42bae7e 378 data4=0x3f;
shina 2:830db42bae7e 379 } else if(left1==1) {
shina 2:830db42bae7e 380 data1=0x3f;
shina 2:830db42bae7e 381 data2=0x4f;
shina 2:830db42bae7e 382 data3=0x3f;
shina 2:830db42bae7e 383 data4=0x4f;
shina 2:830db42bae7e 384 } else {
shina 2:830db42bae7e 385 data1=0x3f;
shina 2:830db42bae7e 386 data2=0x3f;
shina 2:830db42bae7e 387 data3=0x3f;
shina 2:830db42bae7e 388 data4=0x3f;
shina 2:830db42bae7e 389 }
shina 2:830db42bae7e 390 } else if(Ry<-30&&i==1) {
shina 2:830db42bae7e 391 if(right1==1){
shina 2:830db42bae7e 392 data1=0x5f;
shina 2:830db42bae7e 393 data2=0xbf;
shina 2:830db42bae7e 394 data3=0x5f;
shina 2:830db42bae7e 395 data4=0xbf;
shina 2:830db42bae7e 396 }else if(left1==1){
shina 2:830db42bae7e 397 data1=0xbf;
shina 2:830db42bae7e 398 data2=0x5f;
shina 2:830db42bae7e 399 data3=0xbf;
shina 2:830db42bae7e 400 data4=0x5f;
shina 2:830db42bae7e 401 }else{
shina 2:830db42bae7e 402 data1=0xbf;
shina 2:830db42bae7e 403 data2=0xbf;
shina 2:830db42bae7e 404 data3=0xbf;
shina 2:830db42bae7e 405 data4=0xbf;
shina 1:99294241f2ba 406 }
shina 2:830db42bae7e 407 } else if(Rx>30&&i==1) {
shina 2:830db42bae7e 408 if(right1==1) {
shina 2:830db42bae7e 409 data1=0xbf;
shina 2:830db42bae7e 410 data2=0x5f;
shina 2:830db42bae7e 411 data3=0x4f;
shina 2:830db42bae7e 412 data4=0x3f;
shina 2:830db42bae7e 413 } else if(left1==1) {
shina 2:830db42bae7e 414 data1=0x5f;
shina 2:830db42bae7e 415 data2=0xbf;
shina 2:830db42bae7e 416 data3=0x3f;
shina 2:830db42bae7e 417 data4=0x4f;
shina 2:830db42bae7e 418 } else {
shina 2:830db42bae7e 419 data1=0xbf;
shina 2:830db42bae7e 420 data2=0xbf;
shina 2:830db42bae7e 421 data3=0x3f;
shina 2:830db42bae7e 422 data4=0x3f;
shina 1:99294241f2ba 423 }
shina 2:830db42bae7e 424 } else if(Rx<-30&&i==1) {
shina 2:830db42bae7e 425 if(right1==1) {
shina 2:830db42bae7e 426 data1=0x4f;
shina 2:830db42bae7e 427 data2=0x3f;
shina 2:830db42bae7e 428 data3=0xbf;
shina 2:830db42bae7e 429 data4=0x5f;
shina 2:830db42bae7e 430 } else if(left1==1) {
shina 2:830db42bae7e 431 data1=0x3f;
shina 2:830db42bae7e 432 data2=0x4f;
shina 2:830db42bae7e 433 data3=0x5f;
shina 2:830db42bae7e 434 data4=0xbf;
shina 2:830db42bae7e 435 } else {
shina 2:830db42bae7e 436 data1=0x3f;
shina 2:830db42bae7e 437 data2=0x3f;
shina 2:830db42bae7e 438 data3=0xbf;
shina 2:830db42bae7e 439 data4=0xbf;
shina 1:99294241f2ba 440 }
shina 2:830db42bae7e 441 } else if(right1==1&&i==1) {
shina 1:99294241f2ba 442 data1=0xbf;
shina 0:c7e17c2fd542 443 data2=0x3f;
shina 1:99294241f2ba 444 data3=0xbf;
shina 0:c7e17c2fd542 445 data4=0x3f;
shina 2:830db42bae7e 446 } else if(left1==1&&i==1) {
shina 1:99294241f2ba 447 data1=0x3f;
shina 0:c7e17c2fd542 448 data2=0xbf;
shina 1:99294241f2ba 449 data3=0x3f;
shina 0:c7e17c2fd542 450 data4=0xbf;
shina 2:830db42bae7e 451 } else {
shina 0:c7e17c2fd542 452 data1=0x80;
shina 0:c7e17c2fd542 453 data2=0x80;
shina 0:c7e17c2fd542 454 data3=0x80;
shina 0:c7e17c2fd542 455 data4=0x80;
shina 0:c7e17c2fd542 456 }
shina 2:830db42bae7e 457 }
shina 0:c7e17c2fd542 458
shina 1:99294241f2ba 459
shina 2:830db42bae7e 460 //pwm変化
shina 2:830db42bae7e 461 void change_pwm()
shina 2:830db42bae7e 462 {
shina 2:830db42bae7e 463 if(cross!=old_cross) {
shina 2:830db42bae7e 464 old_cross=cross;
shina 2:830db42bae7e 465 if(cross==1) {
shina 2:830db42bae7e 466 if(i==1) {
shina 2:830db42bae7e 467 pwm=0;
shina 2:830db42bae7e 468 data10=0xbf;
shina 2:830db42bae7e 469 send_data(0x40,data10);
shina 2:830db42bae7e 470 i=0;
shina 2:830db42bae7e 471 } else if(i==0) {
shina 2:830db42bae7e 472 pwm=1;
shina 2:830db42bae7e 473 data10=0x3f;
shina 2:830db42bae7e 474 send_data(0x40,data10);
shina 2:830db42bae7e 475 i=1;
shina 0:c7e17c2fd542 476 }
shina 0:c7e17c2fd542 477 }
shina 0:c7e17c2fd542 478 }
shina 0:c7e17c2fd542 479 }
shina 0:c7e17c2fd542 480
shina 0:c7e17c2fd542 481 //サーボモーター
shina 2:830db42bae7e 482 void change_servo()
shina 2:830db42bae7e 483 {
shina 2:830db42bae7e 484 if(right2!=old_right2) {
shina 2:830db42bae7e 485 old_right2=right2;
shina 2:830db42bae7e 486 //ハンガー機構&バスタオル機構initialize処理
shina 2:830db42bae7e 487 if(right2==1) {
shina 2:830db42bae7e 488 if(o==1) {
shina 2:830db42bae7e 489
shina 2:830db42bae7e 490 // timer.start();
shina 2:830db42bae7e 491 // data_servo=0x03;
shina 2:830db42bae7e 492 // send_data(0x18,data_servo);
shina 2:830db42bae7e 493 data_servo=0x01;
shina 2:830db42bae7e 494 //send_data(0x18,data_servo);
shina 2:830db42bae7e 495 o=2;
shina 2:830db42bae7e 496 } else if(o==2) {
shina 2:830db42bae7e 497 data_servo=0x02;
shina 2:830db42bae7e 498 //send_data(0x18,data_servo);
shina 2:830db42bae7e 499 o=3;
shina 2:830db42bae7e 500 }
shina 2:830db42bae7e 501 //data_servo=0x01;
shina 2:830db42bae7e 502 }
shina 2:830db42bae7e 503 } else if(circle!=old_circle) {
shina 2:830db42bae7e 504 old_circle=circle;
shina 2:830db42bae7e 505 //バスタオル挟む機構
shina 2:830db42bae7e 506 if(circle==1) {
shina 2:830db42bae7e 507 if(k==1) {
shina 2:830db42bae7e 508 data_servo=0x03;
shina 2:830db42bae7e 509 //send_data(0x18,data_servo);
shina 2:830db42bae7e 510 k=0;
shina 2:830db42bae7e 511 } else if(k==0) {
shina 2:830db42bae7e 512 data_servo=0x04;
shina 2:830db42bae7e 513 //send_data(0x18,data_servo);
shina 2:830db42bae7e 514 k=1;
shina 2:830db42bae7e 515 }
shina 2:830db42bae7e 516 }
shina 2:830db42bae7e 517 }/*else if(hidari1!=old_hidari1){
shina 1:99294241f2ba 518 old_hidari1=hidari1;
shina 2:830db42bae7e 519
shina 1:99294241f2ba 520 if(hidari1==1&&select==0){
shina 1:99294241f2ba 521 if(n==1){
shina 1:99294241f2ba 522 data_servo=0x05;
shina 1:99294241f2ba 523 n=0;
shina 1:99294241f2ba 524 }else if(n==0){
shina 1:99294241f2ba 525 data_servo=0x06;
shina 1:99294241f2ba 526 n=1;
shina 0:c7e17c2fd542 527 }
shina 0:c7e17c2fd542 528 }
shina 1:99294241f2ba 529 }*/
shina 2:830db42bae7e 530
shina 2:830db42bae7e 531 /* if(timer.read()>2&&o==2){
shina 2:830db42bae7e 532 data_servo=0x04;
shina 2:830db42bae7e 533 send_data(0x18,data_servo);
shina 2:830db42bae7e 534 timer.stop();
shina 2:830db42bae7e 535 timer.reset();
shina 2:830db42bae7e 536 }*/
shina 2:830db42bae7e 537 }
shina 2:830db42bae7e 538
shina 0:c7e17c2fd542 539 //ラック
shina 2:830db42bae7e 540 /*
shina 2:830db42bae7e 541 void change_rack()
shina 2:830db42bae7e 542 {
shina 2:830db42bae7e 543
shina 2:830db42bae7e 544
shina 2:830db42bae7e 545 //右
shina 2:830db42bae7e 546 if(triangle==1&&cross==0&&ue1==0&&shita==0&&(-32<Ly<32)) {
shina 2:830db42bae7e 547 if(!(get_data_rs232 & 0x01)) {
shina 2:830db42bae7e 548 data5=0x00;
shina 2:830db42bae7e 549 } else if(get_data_rs232 & 0x01) {
shina 2:830db42bae7e 550 data5=0x10;
shina 2:830db42bae7e 551 }
shina 2:830db42bae7e 552 } else if(triangle==0&&cross==1&&ue1==0&&shita==0&&(-32<Ly<32)) {
shina 2:830db42bae7e 553 if(!(get_data_rs232 & 0x04)) {
shina 2:830db42bae7e 554 data5=0xff;
shina 2:830db42bae7e 555 } else if(get_data_rs232 & 0x04) {
shina 2:830db42bae7e 556 data5=0x10;
shina 2:830db42bae7e 557 }
shina 1:99294241f2ba 558 //左
shina 2:830db42bae7e 559 } else if(triangle==0&&cross==0&&ue1==1&&shita==0&&(-32<Ly<32)) {
shina 2:830db42bae7e 560 if(!(get_data_rs232 & 0x02)) {
shina 2:830db42bae7e 561 data6=0xff;
shina 2:830db42bae7e 562 } else if(get_data_rs232 & 0x02) {
shina 2:830db42bae7e 563 data6=0x10;
shina 1:99294241f2ba 564 }
shina 2:830db42bae7e 565 } else if(triangle==0&&cross==0&&ue1==0&&shita==1&&(-32<Ly<32)) {
shina 2:830db42bae7e 566 if(!(get_data_rs232 & 0x08)) {
shina 2:830db42bae7e 567 data6=0x00;
shina 2:830db42bae7e 568 } else if(get_data_rs232 & 0x08) {
shina 2:830db42bae7e 569 data6=0x10;
shina 2:830db42bae7e 570 }
shina 2:830db42bae7e 571 } else if(triangle==0&&cross==0&&ue1==0&&shita==0&&(-32<Ly<32)) {
shina 2:830db42bae7e 572 data5=0x80;
shina 2:830db42bae7e 573 data6=0x80;
shina 2:830db42bae7e 574
shina 2:830db42bae7e 575 }
shina 1:99294241f2ba 576
shina 1:99294241f2ba 577 }
shina 2:830db42bae7e 578 */
shina 1:99294241f2ba 579
shina 1:99294241f2ba 580 //ラック左右
shina 2:830db42bae7e 581 void change_rack_2()
shina 2:830db42bae7e 582 {
shina 2:830db42bae7e 583 /*
shina 2:830db42bae7e 584 if(triangle==0&&cross==0&&ue1==0&&shita==0&&Ly>32) {
shina 2:830db42bae7e 585 if(get_data_rs232 & 0x01) {
shina 1:99294241f2ba 586 data5=0x10;
shina 2:830db42bae7e 587 } else {
shina 2:830db42bae7e 588 data5=0x00;
shina 2:830db42bae7e 589 }
shina 2:830db42bae7e 590 if(get_data_rs232 & 0x02) {
shina 1:99294241f2ba 591 data6=0x10;
shina 2:830db42bae7e 592 } else {
shina 0:c7e17c2fd542 593 data6=0xff;
shina 2:830db42bae7e 594 }
shina 2:830db42bae7e 595 } else if(triangle==0&&cross==0&&ue1==0&&shita==0&&Ly<-32) {
shina 2:830db42bae7e 596 if(get_data_rs232 & 0x04) {
shina 2:830db42bae7e 597 data5=0x10;
shina 2:830db42bae7e 598 } else {
shina 2:830db42bae7e 599 data5=0xff;
shina 2:830db42bae7e 600 }
shina 2:830db42bae7e 601 if(get_data_rs232 & 0x08) {
shina 1:99294241f2ba 602 data6=0x10;
shina 2:830db42bae7e 603 } else {
shina 2:830db42bae7e 604 data6=0x00;
shina 2:830db42bae7e 605 }
shina 2:830db42bae7e 606 } else if(triangle==0&&cross==0&&ue1==0&&shita==0&&(-32<Ly<32)) {
shina 2:830db42bae7e 607 data5=0x80;
shina 2:830db42bae7e 608 data6=0x80;
shina 2:830db42bae7e 609 }
shina 2:830db42bae7e 610 */
shina 2:830db42bae7e 611
shina 2:830db42bae7e 612 if(ue1!=old_ue1){
shina 2:830db42bae7e 613 old_ue1=ue1;
shina 2:830db42bae7e 614 if(ue1==1&&start==0){
shina 1:99294241f2ba 615 data5=0x00;
shina 1:99294241f2ba 616 data6=0xff;
shina 3:82008ebeb93c 617
shina 3:82008ebeb93c 618 /*data_servo=0x03;
shina 3:82008ebeb93c 619 send_data(0x18,data_servo);
shina 3:82008ebeb93c 620 data_servo=0x04;
shina 3:82008ebeb93c 621 send_data(0x18,data_servo);*/
shina 1:99294241f2ba 622 }
shina 2:830db42bae7e 623 }else if(shita!=old_shita){
shina 2:830db42bae7e 624 old_shita=shita;
shina 2:830db42bae7e 625 if(shita==1&&start==0){
shina 1:99294241f2ba 626 data5=0xff;
shina 1:99294241f2ba 627 data6=0x00;
shina 1:99294241f2ba 628 }
shina 2:830db42bae7e 629 }
shina 2:830db42bae7e 630
shina 2:830db42bae7e 631 if((get_data_rs232 & 0x01)&&data5==0x00){
shina 2:830db42bae7e 632 data5=0x10;
shina 2:830db42bae7e 633 send_data(0x20,data5);
shina 2:830db42bae7e 634 }else if((get_data_rs232 & 0x04)&&data5==0xff){
shina 2:830db42bae7e 635 data5=0x10;
shina 2:830db42bae7e 636 send_data(0x20,data5);
shina 0:c7e17c2fd542 637 }
shina 2:830db42bae7e 638
shina 2:830db42bae7e 639 if((get_data_rs232 & 0x02)&&data6==0xff){
shina 2:830db42bae7e 640 data6=0x10;
shina 2:830db42bae7e 641 send_data(0x22,data6);
shina 2:830db42bae7e 642 }else if((get_data_rs232 & 0x08)&&data6==0x00){
shina 2:830db42bae7e 643 data6=0x10;
shina 2:830db42bae7e 644 send_data(0x22,data6);
shina 2:830db42bae7e 645 }
shina 2:830db42bae7e 646
shina 2:830db42bae7e 647
shina 1:99294241f2ba 648 }
shina 0:c7e17c2fd542 649
shina 0:c7e17c2fd542 650 //回収機構
shina 3:82008ebeb93c 651
shina 2:830db42bae7e 652 void sequence_kaisyu()
shina 2:830db42bae7e 653 {
shina 2:830db42bae7e 654 if(q==0){
shina 2:830db42bae7e 655 if(square!=old_square) {
shina 2:830db42bae7e 656 old_square=square;
shina 3:82008ebeb93c 657 if(square==1&&select==0) {
shina 3:82008ebeb93c 658
shina 2:830db42bae7e 659 data_servo=0x07;
shina 2:830db42bae7e 660 send_data(0x18,data_servo);
shina 3:82008ebeb93c 661 wait(1.3);
shina 2:830db42bae7e 662 data7=0x00;
shina 3:82008ebeb93c 663 get_data_rs232=get_data_rs232 & 0b11101111;
shina 2:830db42bae7e 664 while(!(get_data_rs232 & 0x10)) {
shina 2:830db42bae7e 665 send_data(0x24,data7);
shina 2:830db42bae7e 666 get_data_rs232=slave.getc();
shina 2:830db42bae7e 667 }
shina 2:830db42bae7e 668 data7=0x10;
shina 2:830db42bae7e 669 send_data(0x24,data7);
shina 2:830db42bae7e 670 data_servo=0x08;
shina 2:830db42bae7e 671 send_data(0x18,data_servo);
shina 3:82008ebeb93c 672 wait(1.3);
shina 2:830db42bae7e 673 data7=0xff;
shina 3:82008ebeb93c 674 get_data_rs232=get_data_rs232 & 0b11011111;
shina 2:830db42bae7e 675 while(!(get_data_rs232 & 0x20)) {
shina 2:830db42bae7e 676 send_data(0x24,data7);
shina 2:830db42bae7e 677 get_data_rs232=slave.getc();
shina 2:830db42bae7e 678 }
shina 2:830db42bae7e 679 data7=0x10;
shina 2:830db42bae7e 680 send_data(0x24,data7);
shina 3:82008ebeb93c 681
shina 3:82008ebeb93c 682 }
shina 3:82008ebeb93c 683 }else if(triangle!=old_triangle){
shina 3:82008ebeb93c 684 if(triangle==1&&select==0){
shina 3:82008ebeb93c 685
shina 3:82008ebeb93c 686 data_servo=0x07;
shina 3:82008ebeb93c 687 send_data(0x18,data_servo);
shina 3:82008ebeb93c 688 wait(1.3);
shina 3:82008ebeb93c 689 data7=0x00;
shina 3:82008ebeb93c 690 send_data(0x24,data7);
shina 3:82008ebeb93c 691 wait(0.3);
shina 3:82008ebeb93c 692 data7=0x10;
shina 3:82008ebeb93c 693 send_data(0x24,data7);
shina 3:82008ebeb93c 694 data_servo=0x08;
shina 3:82008ebeb93c 695 send_data(0x18,data_servo);
shina 3:82008ebeb93c 696 wait(1.3);
shina 3:82008ebeb93c 697 data7=0xff;
shina 3:82008ebeb93c 698 get_data_rs232=get_data_rs232 & 0b11011111;
shina 3:82008ebeb93c 699 while(!(get_data_rs232 & 0x20)) {
shina 3:82008ebeb93c 700 send_data(0x24,data7);
shina 3:82008ebeb93c 701 get_data_rs232=slave.getc();
shina 3:82008ebeb93c 702 }
shina 3:82008ebeb93c 703 data7=0x10;
shina 3:82008ebeb93c 704 send_data(0x24,data7);
shina 2:830db42bae7e 705 }
shina 2:830db42bae7e 706 }
shina 2:830db42bae7e 707 }
shina 2:830db42bae7e 708 }
shina 2:830db42bae7e 709
shina 2:830db42bae7e 710
shina 3:82008ebeb93c 711 /*
shina 2:830db42bae7e 712 void kaisyu(){
shina 2:830db42bae7e 713 if(q==0){
shina 2:830db42bae7e 714 if(old_square!=square){
shina 2:830db42bae7e 715 old_square=square;
shina 2:830db42bae7e 716 if(square==1){
shina 2:830db42bae7e 717 p=1;
shina 2:830db42bae7e 718
shina 2:830db42bae7e 719 }
shina 2:830db42bae7e 720 }
shina 2:830db42bae7e 721 switch(p){
shina 2:830db42bae7e 722
shina 2:830db42bae7e 723 case 1:
shina 2:830db42bae7e 724 data_servo=0x07;
shina 2:830db42bae7e 725 send_data(0x24,data_servo);
shina 2:830db42bae7e 726 timer2.start();
shina 2:830db42bae7e 727 if(timer2.read()>3.5){
shina 2:830db42bae7e 728 timer2.stop();
shina 2:830db42bae7e 729 timer2.reset();
shina 2:830db42bae7e 730 p=2;
shina 2:830db42bae7e 731 }
shina 2:830db42bae7e 732 break;
shina 2:830db42bae7e 733
shina 2:830db42bae7e 734 case 2:
shina 2:830db42bae7e 735 data7=0x00;
shina 2:830db42bae7e 736 send_data(0x24,data7);
shina 2:830db42bae7e 737 if(get_data_rs232 & 0x10){
shina 2:830db42bae7e 738 data7=0x10;
shina 2:830db42bae7e 739 send_data(0x24,data7);
shina 2:830db42bae7e 740 p=3;
shina 2:830db42bae7e 741 }
shina 2:830db42bae7e 742 break;
shina 2:830db42bae7e 743
shina 2:830db42bae7e 744 case 3:
shina 2:830db42bae7e 745 data_servo=0x08;
shina 2:830db42bae7e 746 send_data(0x18,data_servo);
shina 2:830db42bae7e 747 timer2.start();
shina 2:830db42bae7e 748 if(timer2.read()>1.3){
shina 2:830db42bae7e 749 p=4;
shina 2:830db42bae7e 750 }
shina 2:830db42bae7e 751
shina 2:830db42bae7e 752 break;
shina 2:830db42bae7e 753
shina 2:830db42bae7e 754 case 4:
shina 2:830db42bae7e 755 data7=0xff;
shina 2:830db42bae7e 756 send_data(0x24,data7);
shina 2:830db42bae7e 757 if(get_data_rs232 & 0x20){
shina 2:830db42bae7e 758 data7=0x10;
shina 2:830db42bae7e 759 send_data(0x24,data7);
shina 2:830db42bae7e 760 p=5;
shina 2:830db42bae7e 761 }
shina 2:830db42bae7e 762 break;
shina 2:830db42bae7e 763
shina 2:830db42bae7e 764 default:
shina 2:830db42bae7e 765 p=5;
shina 2:830db42bae7e 766 break;
shina 2:830db42bae7e 767
shina 2:830db42bae7e 768 }
shina 2:830db42bae7e 769 }
shina 2:830db42bae7e 770 }
shina 3:82008ebeb93c 771 */
shina 2:830db42bae7e 772
shina 2:830db42bae7e 773 /*
shina 2:830db42bae7e 774 void sequence_hakidashi()
shina 2:830db42bae7e 775 {
shina 2:830db42bae7e 776 if(q==0){
shina 2:830db42bae7e 777 if(migi1!=old_migi1) {
shina 2:830db42bae7e 778 old_migi1=migi1;
shina 2:830db42bae7e 779 if(migi1==1&&select==0) {
shina 2:830db42bae7e 780 data_servo=0x07;
shina 2:830db42bae7e 781 send_data(0x18,data_servo);
shina 2:830db42bae7e 782 wait(1);
shina 2:830db42bae7e 783 data7=0x00;
shina 2:830db42bae7e 784 send_data(0x24,data7);
shina 2:830db42bae7e 785 wait(0.5);
shina 2:830db42bae7e 786 data7=0x10;
shina 2:830db42bae7e 787 send_data(0x24,data7);
shina 2:830db42bae7e 788 data11=0xff;
shina 2:830db42bae7e 789 while(!(get_data_rs232 & 0x40)){
shina 2:830db42bae7e 790 send_data(0x30,data11);
shina 2:830db42bae7e 791 get_data_rs232=slave.getc();
shina 2:830db42bae7e 792 }
shina 2:830db42bae7e 793 data11=0x10;
shina 2:830db42bae7e 794 send_data(0x38,data11);
shina 2:830db42bae7e 795 data11=0x00;
shina 2:830db42bae7e 796 while(!(get_data_rs232 & 0x80)){
shina 2:830db42bae7e 797 send_data(0x30,data11);
shina 2:830db42bae7e 798 get_data_rs232=slave.getc();
shina 2:830db42bae7e 799 }
shina 2:830db42bae7e 800 data11=0x10;
shina 2:830db42bae7e 801 send_data(0x30,data11);
shina 2:830db42bae7e 802 data7=0xff;
shina 2:830db42bae7e 803 while(!(get_data_rs232 & 0x20)){
shina 2:830db42bae7e 804 send_data(0x24,data7);
shina 2:830db42bae7e 805 get_data_rs232=slave.getc();
shina 2:830db42bae7e 806 }
shina 2:830db42bae7e 807 data7=0x10;
shina 2:830db42bae7e 808 send_data(0x24,data7);
shina 2:830db42bae7e 809
shina 2:830db42bae7e 810 }
shina 2:830db42bae7e 811 }
shina 2:830db42bae7e 812 }
shina 2:830db42bae7e 813 }
shina 2:830db42bae7e 814 */
shina 2:830db42bae7e 815
shina 3:82008ebeb93c 816 /*
shina 3:82008ebeb93c 817 void sequence_kaisyu_short(){
shina 3:82008ebeb93c 818 if(q==0){
shina 3:82008ebeb93c 819 if(old_triangle!=triangle){
shina 3:82008ebeb93c 820 old_triangle=triangle;
shina 3:82008ebeb93c 821 if(triangle==1){
shina 3:82008ebeb93c 822
shina 3:82008ebeb93c 823 data_servo=0x07;
shina 3:82008ebeb93c 824 send_data(0x18,data_servo);
shina 3:82008ebeb93c 825 wait(1.3);
shina 3:82008ebeb93c 826 data7=0x00;
shina 3:82008ebeb93c 827 send_data(0x24,data7);
shina 3:82008ebeb93c 828 wait(0.3);
shina 3:82008ebeb93c 829 data7=0x10;
shina 3:82008ebeb93c 830 send_data(0x24,data7);
shina 3:82008ebeb93c 831 data_servo=0x08;
shina 3:82008ebeb93c 832 send_data(0x18,data_servo);
shina 3:82008ebeb93c 833 wait(1.3);
shina 3:82008ebeb93c 834 data7=0xff;
shina 3:82008ebeb93c 835 get_data_rs232=get_data_rs232 & 0x;
shina 3:82008ebeb93c 836 while(!(get_data_rs232 & 0x20)) {
shina 3:82008ebeb93c 837 send_data(0x24,data7);
shina 3:82008ebeb93c 838 get_data_rs232=slave.getc();
shina 3:82008ebeb93c 839 }
shina 3:82008ebeb93c 840 data7=0x10;
shina 3:82008ebeb93c 841 send_data(0x24,data7);
shina 3:82008ebeb93c 842
shina 3:82008ebeb93c 843 }
shina 3:82008ebeb93c 844 }
shina 3:82008ebeb93c 845 }
shina 3:82008ebeb93c 846 }*/
shina 1:99294241f2ba 847
shina 2:830db42bae7e 848 void hakidashi(){
shina 2:830db42bae7e 849 if(q==0){
shina 2:830db42bae7e 850 if(old_migi1!=migi1){
shina 2:830db42bae7e 851 old_migi1=migi1;
shina 3:82008ebeb93c 852 if(migi1==1&&select==0){
shina 2:830db42bae7e 853 r=1;
shina 2:830db42bae7e 854 }
shina 2:830db42bae7e 855 }
shina 2:830db42bae7e 856
shina 2:830db42bae7e 857 switch(r){
shina 2:830db42bae7e 858 case 1:
shina 2:830db42bae7e 859 data_servo=0x07;
shina 2:830db42bae7e 860 send_data(0x18,data_servo);
shina 2:830db42bae7e 861 timer2.start();
shina 2:830db42bae7e 862 if(timer2.read()>1.5){
shina 2:830db42bae7e 863 timer2.stop();
shina 2:830db42bae7e 864 timer2.reset();
shina 2:830db42bae7e 865 r=2;
shina 2:830db42bae7e 866 }
shina 2:830db42bae7e 867 break;
shina 2:830db42bae7e 868
shina 2:830db42bae7e 869 case 2:
shina 2:830db42bae7e 870 data7=0x00;
shina 2:830db42bae7e 871 send_data(0x24,data7);
shina 2:830db42bae7e 872 timer2.start();
shina 2:830db42bae7e 873 if(timer2.read()>0.3){
shina 2:830db42bae7e 874 timer2.stop();
shina 2:830db42bae7e 875 timer2.reset();
shina 2:830db42bae7e 876 data7=0x10;
shina 2:830db42bae7e 877 send_data(0x24,data7);
shina 2:830db42bae7e 878 r=3;
shina 2:830db42bae7e 879 }
shina 2:830db42bae7e 880 break;
shina 2:830db42bae7e 881
shina 2:830db42bae7e 882 case 3:
shina 2:830db42bae7e 883 data11=0xff;
shina 2:830db42bae7e 884 send_data(0x30,data11);
shina 2:830db42bae7e 885 if(get_data_rs232 & 0x40){
shina 2:830db42bae7e 886 data11=0x10;
shina 2:830db42bae7e 887 send_data(0x30,data11);
shina 2:830db42bae7e 888 r=4;
shina 2:830db42bae7e 889 }
shina 2:830db42bae7e 890 break;
shina 2:830db42bae7e 891
shina 2:830db42bae7e 892 case 4:
shina 2:830db42bae7e 893 data11=0x00;
shina 2:830db42bae7e 894 send_data(0x30,data11);
shina 2:830db42bae7e 895 if(get_data_rs232 & 0x80){
shina 2:830db42bae7e 896 data11=0x10;
shina 2:830db42bae7e 897 send_data(0x30,data11);
shina 2:830db42bae7e 898 r=5;
shina 2:830db42bae7e 899 }
shina 2:830db42bae7e 900 break;
shina 2:830db42bae7e 901
shina 2:830db42bae7e 902 case 5:
shina 2:830db42bae7e 903 data7=0xff;
shina 2:830db42bae7e 904 send_data(0x24,data7);
shina 2:830db42bae7e 905 if(get_data_rs232 & 0x20){
shina 2:830db42bae7e 906 data7=0x10;
shina 2:830db42bae7e 907 send_data(0x24,data7);
shina 2:830db42bae7e 908 r=6;
shina 2:830db42bae7e 909 }
shina 2:830db42bae7e 910 break;
shina 2:830db42bae7e 911
shina 2:830db42bae7e 912 default:
shina 2:830db42bae7e 913 r=6;
shina 2:830db42bae7e 914 break;
shina 2:830db42bae7e 915 }
shina 2:830db42bae7e 916 }
shina 2:830db42bae7e 917 }
shina 2:830db42bae7e 918
shina 3:82008ebeb93c 919
shina 2:830db42bae7e 920
shina 2:830db42bae7e 921 //ファン
shina 2:830db42bae7e 922 void change_fan()
shina 2:830db42bae7e 923 {
shina 2:830db42bae7e 924 if(q==1){
shina 2:830db42bae7e 925 if(left2==1&&(old_triangle==triangle)) {
shina 2:830db42bae7e 926 data8=0xff;
shina 2:830db42bae7e 927 data9=0xff;
shina 2:830db42bae7e 928 data10=0xff;
shina 2:830db42bae7e 929 } else if(left2==0&&(old_triangle==triangle)) {
shina 2:830db42bae7e 930 data8=0x00;
shina 2:830db42bae7e 931 data9=0x00;
shina 2:830db42bae7e 932 data10=0x00;
shina 2:830db42bae7e 933 }else if(left2==0&&(old_triangle!=triangle)&&select==0){
shina 2:830db42bae7e 934 old_triangle=triangle;
shina 2:830db42bae7e 935 if(triangle==1){
shina 2:830db42bae7e 936 data8=0xff;
shina 2:830db42bae7e 937 data9=0xff;
shina 2:830db42bae7e 938 data10=0xff;
shina 2:830db42bae7e 939 data_servo=0x03;
shina 2:830db42bae7e 940 send_data(0x26,data8);
shina 2:830db42bae7e 941 send_data(0x28,data9);
shina 2:830db42bae7e 942 send_data(0x40,data10);
shina 2:830db42bae7e 943 wait(0.5);
shina 2:830db42bae7e 944 send_data(0x18,data_servo);
shina 2:830db42bae7e 945 wait(1);
shina 2:830db42bae7e 946 data8=0x00;
shina 2:830db42bae7e 947 data9=0x00;
shina 2:830db42bae7e 948 data10=0x00;
shina 2:830db42bae7e 949 send_data(0x26,data8);
shina 2:830db42bae7e 950 send_data(0x28,data9);
shina 2:830db42bae7e 951 send_data(0x40,data10);
shina 2:830db42bae7e 952 wait(0.5);
shina 2:830db42bae7e 953 data_servo=0x04;
shina 2:830db42bae7e 954 send_data(0x18,data_servo);
shina 2:830db42bae7e 955 }
shina 2:830db42bae7e 956 }
shina 2:830db42bae7e 957 }
shina 2:830db42bae7e 958
shina 1:99294241f2ba 959 }
shina 1:99294241f2ba 960
shina 0:c7e17c2fd542 961 //i2c
shina 2:830db42bae7e 962 void send_data(char address,char data)
shina 2:830db42bae7e 963 {
shina 0:c7e17c2fd542 964 tsushin=1;
shina 0:c7e17c2fd542 965 tushin_check=0;
shina 0:c7e17c2fd542 966 i2c.start();
shina 0:c7e17c2fd542 967 i2c.write(address);
shina 0:c7e17c2fd542 968 tushin_check=i2c.write(data);
shina 0:c7e17c2fd542 969 i2c.stop();
shina 2:830db42bae7e 970 }
shina 2:830db42bae7e 971