'use strict';

goog.provide('Blockly.Arduino.Lizard');

goog.require('Blockly.Arduino');

// 设置数字量
Blockly.Arduino.Lizard_digital_write = function() {
  var dropdown_pin = this.getTitleValue('PIN');
  var dropdown_stat = this.getTitleValue('STAT');
  Blockly.Arduino.definitions_['include_Lizard'] = '#include "Lizard.h"';
  Blockly.Arduino.setups_['setup_output_'+dropdown_pin] = 'pinMode('+dropdown_pin+', OUTPUT);';
  var code = 'digitalWrite('+dropdown_pin+','+dropdown_stat+');\n'
  return code;
};

// 读数字量
Blockly.Arduino.Lizard_digital_read = function() {
  var dropdown_pin = this.getTitleValue('PIN');
  var dropdown_stat = this.getTitleValue('STAT');
  Blockly.Arduino.definitions_['include_Lizard'] = '#include "Lizard.h"';
  Blockly.Arduino.setups_['setup_input_'+dropdown_pin] = 'pinMode('+dropdown_pin+', INPUT);';

  
  var code = +dropdown_stat+'==digitalRead('+dropdown_pin+')';
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};


// 设置PWM
Blockly.Arduino.Lizard_analog_write = function() {
  var dropdown_pin = this.getTitleValue('PIN');
  //var dropdown_stat = this.getTitleValue('STAT');
  var value_num = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
  //Blockly.Arduino.setups_['setup_output'+dropdown_pin] = 'pinMode('+dropdown_pin+', OUTPUT);';
  var code = 'analogWrite('+dropdown_pin+','+value_num+');\n';

  return code;
};



// 读模拟口
Blockly.Arduino.Lizard_analog_read = function() {
  Blockly.Arduino.definitions_['include_Lizard'] = '#include "Lizard.h"';
  var dropdown_pin = this.getTitleValue('PIN');
  var code = 'analogRead('+dropdown_pin+')';
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};




//舵机

Blockly.Arduino.Lizard_duoji = function() {
var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  var value_degree = Blockly.Arduino.valueToCode(this, 'DEGREE', Blockly.Arduino.ORDER_ATOMIC);
  
  Blockly.Arduino.definitions_['define_DJ'] = '#include <Servo.h>';
   Blockly.Arduino.definitions_['var_servo'+dropdown_pin] = 'Servo servo_'+dropdown_pin+';';
  
   Blockly.Arduino.setups_['setup_servo_'+dropdown_pin] = 'servo_'+dropdown_pin+'.attach('+dropdown_pin+');';
  var code = 'servo_'+dropdown_pin+'.write(i) ;\n';
  return code;
};

Blockly.Arduino.Lizard_dj = function() {
  var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  var value_degree = Blockly.Arduino.valueToCode(this, 'DEGREE', Blockly.Arduino.ORDER_ATOMIC);
  //value_degree = value_degree.replace('(','').replace(')','')
  var delay_time = Blockly.Arduino.valueToCode(this, 'DELAY_TIME', Blockly.Arduino.ORDER_ATOMIC) || '0'
  //delay_time = delay_time.replace('(','').replace(')','');
  
  Blockly.Arduino.definitions_['define_servo'] = '#include <Servo.h>';
  Blockly.Arduino.definitions_['var_servo'+dropdown_pin] = 'Servo servo_'+dropdown_pin+';';
  Blockly.Arduino.setups_['setup_servo_'+dropdown_pin] = 'servo_'+dropdown_pin+'.attach('+dropdown_pin+');';
  
  var code = 'servo_'+dropdown_pin+'.write('+value_degree+');\n'+'delay(' + delay_time + ');\n';
  return code;
};









//红外测试模块
Blockly.Arduino.Lizard_ir = function() {
  var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['define_irev'] = '#include <IRremote.h>';
  Blockly.Arduino.definitions_['define_ireve'+dropdown_pin] = 'int RECV_PIN ='+dropdown_pin+';';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = 'IRrecv irrecv(RECV_PIN);\ndecode_results results;\n';
  Blockly.Arduino.setups_['setup_input_'] = '\nirrecv.enableIRIn();';
  var code = 'if (irrecv.decode(&results))\n{\nSerial.println(results.value, HEX);\nirrecv.resume();\n}\n';
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};


//校准
Blockly.Arduino.Lizard_Xiyi_jiaozhun = function() {
   var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  
  Blockly.Arduino.setups_['setup_jz_'] = 'myservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\nmyservo1.write(mylist[0]);\n myservo2.write(mylist[1]);\nmyservo3.write(mylist[2]);';
  var code = 'myservo1.write(mylist[0]);\nmyservo2.write(mylist[1]);\nmyservo3.write(mylist[2]);\n';
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};

//前进
/*Blockly.Arduino.Lizard_Xiyi_go = function() {
var x = Blockly.Arduino.valueToCode(this, 'X', Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint  delayedTime1 = 10-('+ x+');  \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nlong KEY_CODE_2 = 0xFF18E7;\n';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = '\nmyservo1.attach(2);\nmyservo3.attach(4);\nwaistOne();\nstepOne();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistBack();\nstepBack(); \ndelay(100);\nwhile(1)\n';  
  return code ;
};*/

Blockly.Arduino.Lizard_Xiyi_gg = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();\nvoid waistTurnleft();\nvoid stepTurnleft();\nvoid waistTurnleft2();\nvoid stepTurnleft2();\nvoid waistTurnright();\nvoid stepTurnright();\nvoid waistTurnright2();\nvoid stepTurnright2();\n';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint  delayedTime1 = 6-('+dropdown_pin+');  \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nlong KEY_CODE_2 = 0xFF18E7;\nvoid waistTurnleft() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}array_setup[1] = array_setup[1] + angle2;}\nvoid stepTurnleft(){\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] + angle3;\narray_setup[2] = array_setup[2] +angle3;}\nvoid waistTurnleft2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2;}\nvoid stepTurnleft2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3; }\nvoid turnLeftbacktwo() {\nfor(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);}\n array_setup[2] = array_setup[2] - angle3;}\nlong KEY_CODE_4 = 0xFF10EF;\nvoid waistTurnright() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2; }\nvoid stepTurnright() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] -i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3;\narray_setup[2] = array_setup[2] - angle3; }\nvoid waistTurnright2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1); }\narray_setup[1] = array_setup[1] + angle2; }\nvoid stepTurnright2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\ndelay(delayedTime1);}\narray_setup[0] = array_setup[0] + angle3;}\nlong KEY_CODE_6 = 0xFF5AA5;\nlong KEY_CODE_8 = 0xFF4AB5;\nvoid turnRightbacktwo() {\n for(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[2] = array_setup[2] + angle3; }';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = '\nmyservo1.attach(2);\nmyservo3.attach(4);\nwaistOne();\nstepOne();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistBack();\nstepBack(); \ndelay(100);\n';  
  return code;
};

//后退
Blockly.Arduino.Lizard_Xiyi_bb = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();\nvoid waistTurnleft();\nvoid stepTurnleft();\nvoid waistTurnleft2();\nvoid stepTurnleft2();\nvoid waistTurnright();\nvoid stepTurnright();\nvoid waistTurnright2();\nvoid stepTurnright2();\n';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint  delayedTime1 = 6-('+dropdown_pin+');  \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nlong KEY_CODE_2 = 0xFF18E7;\nvoid waistTurnleft() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}array_setup[1] = array_setup[1] + angle2;}\nvoid stepTurnleft(){\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] + angle3;\narray_setup[2] = array_setup[2] +angle3;}\nvoid waistTurnleft2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2;}\nvoid stepTurnleft2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3; }\nvoid turnLeftbacktwo() {\nfor(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);}\n array_setup[2] = array_setup[2] - angle3;}\nlong KEY_CODE_4 = 0xFF10EF;\nvoid waistTurnright() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2; }\nvoid stepTurnright() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] -i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3;\narray_setup[2] = array_setup[2] - angle3; }\nvoid waistTurnright2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1); }\narray_setup[1] = array_setup[1] + angle2; }\nvoid stepTurnright2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\ndelay(delayedTime1);}\narray_setup[0] = array_setup[0] + angle3;}\nlong KEY_CODE_6 = 0xFF5AA5;\nlong KEY_CODE_8 = 0xFF4AB5;\nvoid turnRightbacktwo() {\n for(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[2] = array_setup[2] + angle3; }';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = '\nmyservo1.attach(4);\nmyservo3.attach(2);\nwaistOne();\nstepOne();\n waistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistBack();\nstepBack(); \ndelay(100);\n';  
  return code;
};

 /*  Blockly.Arduino.Lizard_Xiyi_bb = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();';
  Blockly.Arduino.definitions_['define_irevec'] ='\nint array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\n int delayedTime1 = 6-('+dropdown_pin+'); \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nlong KEY_CODE_8 = 0xFF4AB5;\n';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = 'myservo1.attach(4);\nmyservo3.attach(2);\nwaistOne();\nstepOne();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistBack();\nstepBack();\n delay(100);\n'; 
  return code ;
};   * 

//左转
/*Blockly.Arduino.Lizard_Xiyi_cc = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistTurnleft();\nvoid stepTurnleft();\nvoid waistTurnleft2();\nvoid stepTurnleft2();';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\n\
                                                  int angle1 = 25,angle2 = 35,angle3 = 55;\n  int delayedTime1 = 6-('+dropdown_pin+');\nvoid waistTurnleft()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle2;\n}\nvoid stepTurnleft()\n{\nfor(int i = 0;i < angle3;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle3;\narray_setup[2] = array_setup[2] +angle3;\n}\nvoid waistTurnleft2()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - angle2;\n}\nvoid stepTurnleft2()\n{\nfor(int i = 0;i < angle3;i++)\n{\nmyservo1.write(array_setup[0] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle3;\n}\nvoid turnLeftbacktwo()\n{\nfor(int i = 0;i < angle3;i++)\n{\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\n array_setup[2] = array_setup[2] - angle3;\n}\nlong KEY_CODE_4 = 0xFF10EF;';
  Blockly.Arduino.setups_['setup_input_'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = 'myservo1.attach(2);\nmyservo3.attach(4);\nwaistTurnleft();\nstepTurnleft();\nwaistTurnleft2();\nstepTurnleft2();\nturnLeftbacktwo();\ndelay(100);\n'; 
  
  return code;
};*/
Blockly.Arduino.Lizard_Xiyi_cc = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();\nvoid waistTurnleft();\nvoid stepTurnleft();\nvoid waistTurnleft2();\nvoid stepTurnleft2();\nvoid waistTurnright();\nvoid stepTurnright();\nvoid waistTurnright2();\nvoid stepTurnright2();\n';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint  delayedTime1 = 6-('+dropdown_pin+');  \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nlong KEY_CODE_2 = 0xFF18E7;\nvoid waistTurnleft() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}array_setup[1] = array_setup[1] + angle2;}\nvoid stepTurnleft(){\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] + angle3;\narray_setup[2] = array_setup[2] +angle3;}\nvoid waistTurnleft2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2;}\nvoid stepTurnleft2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3; }\nvoid turnLeftbacktwo() {\nfor(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);}\n array_setup[2] = array_setup[2] - angle3;}\nlong KEY_CODE_4 = 0xFF10EF;\nvoid waistTurnright() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2; }\nvoid stepTurnright() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] -i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3;\narray_setup[2] = array_setup[2] - angle3; }\nvoid waistTurnright2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1); }\narray_setup[1] = array_setup[1] + angle2; }\nvoid stepTurnright2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\ndelay(delayedTime1);}\narray_setup[0] = array_setup[0] + angle3;}\nlong KEY_CODE_6 = 0xFF5AA5;\nlong KEY_CODE_8 = 0xFF4AB5;\n void turnRightbacktwo() {\n for(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[2] = array_setup[2] + angle3; }';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = '\nmyservo1.attach(2);\nmyservo3.attach(4);\nwaistTurnleft();\nstepTurnleft();\n waistTurnleft2();\n stepTurnleft2();\n\n turnLeftbacktwo(); \ndelay(100);\n';  
  return code;
};
//右转

Blockly.Arduino.Lizard_Xiyi_dd = function() {
 var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();\nvoid waistTurnleft();\nvoid stepTurnleft();\nvoid waistTurnleft2();\nvoid stepTurnleft2();\nvoid waistTurnright();\nvoid stepTurnright();\nvoid waistTurnright2();\nvoid stepTurnright2();\n';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint  delayedTime1 = 6-('+dropdown_pin+');  \nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nlong KEY_CODE_2 = 0xFF18E7;\nvoid waistTurnleft() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}array_setup[1] = array_setup[1] + angle2;}\nvoid stepTurnleft(){\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] + angle3;\narray_setup[2] = array_setup[2] +angle3;}\nvoid waistTurnleft2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2;}\nvoid stepTurnleft2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3; }\nvoid turnLeftbacktwo() {\nfor(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);}\n array_setup[2] = array_setup[2] - angle3;}\nlong KEY_CODE_4 = 0xFF10EF;\nvoid waistTurnright() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);}\narray_setup[1] = array_setup[1] - angle2; }\nvoid stepTurnright() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] -i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1); }\narray_setup[0] = array_setup[0] - angle3;\narray_setup[2] = array_setup[2] - angle3; }\nvoid waistTurnright2() {\nfor(int i = 0;i < angle2;i++) {\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1); }\narray_setup[1] = array_setup[1] + angle2; }\nvoid stepTurnright2() {\nfor(int i = 0;i < angle3;i++) {\nmyservo1.write(array_setup[0] + i);\ndelay(delayedTime1);}\narray_setup[0] = array_setup[0] + angle3;}\nlong KEY_CODE_6 = 0xFF5AA5;\nlong KEY_CODE_8 = 0xFF4AB5;\nvoid turnRightbacktwo() {\n for(int i = 0;i < angle3;i++) {\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1); }\narray_setup[2] = array_setup[2] + angle3; }';
  Blockly.Arduino.setups_['setup_input_w'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = '\nmyservo1.attach(2);\nmyservo3.attach(4);\n waistTurnright();\nstepTurnright();\n  waistTurnright2();\n stepTurnright2();\nturnRightbacktwo();\ndelay(100);\n';  
  return code;
};
/*Blockly.Arduino.Lizard_Xiyi_dd = function() {
  var dropdown_pin = this.getTitleValue('PIN');
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n#include <IRremote.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistTurnright();\nvoid stepTurnright();\nvoid waistTurnright2();\nvoid stepTurnright2();';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint delayedTime1 = 6-('+dropdown_pin+');\nvoid waistTurnright()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - angle2;\n}\nvoid stepTurnright()\n{\nfor(int i = 0;i < angle3;i++)\n{\n myservo1.write(array_setup[0] -i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle3;\narray_setup[2] = array_setup[2] - angle3;\n}\nvoid waistTurnright2()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle2;\n}\nvoid stepTurnright2()\n{\nfor(int i = 0;i < angle3;i++)\n{\nmyservo1.write(array_setup[0] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle3;\n}\nvoid turnLeftbacktwo()\n{\nfor(int i = 0;i < angle3;i++)\n{\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\n array_setup[2] = array_setup[2] + angle3;\n}\nlong KEY_CODE_6 = 0xFF5AA5;\n';
  Blockly.Arduino.setups_['setup_input_'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = 'myservo1.attach(2);\nmyservo3.attach(4);\nwaistTurnright();\nstepTurnright();\nwaistTurnright2();\nstepTurnright2();\nturnLeftbacktwo();\ndelay(100);\n'; 
  return code;
}; */
//加速前进
Blockly.Arduino.Lizard_Xiyi_add = function() {
 var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n#include <IRremote.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();';
  Blockly.Arduino.definitions_['define_irevec'] ='int array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint delayedTime1 = 5;\n';
  Blockly.Arduino.setups_['setup_add_'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = 'myservo1.attach(2);\nmyservo3.attach(4);\ndelayedTime1 = 3;\nwaistOne();\nstepOne();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\n  waistTwo();\n stepTwo();\n waistThree();\nstepThree();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistTwo();\nstepTwo();\n waistThree();\n stepThree();\nwaistBack();\nstepBack();\ndelayedTime1 = 5;\n} \nwhile(1);\n}\nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\nfor(int i=0;i<10;i++)\n{'; 
  return code;
};
//加速后退
Blockly.Arduino.Lizard_Xiyi_sub = function() {
 var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['define_irev'] = '#include <Servo.h>\n#include <IRremote.h>';
  Blockly.Arduino.definitions_['define_ireve'] = 'Servo myservo1;\nServo myservo2;\nServo myservo3;';                                                                                                                                                                                                                                                                                               
  Blockly.Arduino.definitions_['define_ire'] = '\nvoid waistOne();\nvoid stepOne();\nvoid waistTwo();\nvoid stepTwo();\nvoid waistThree();\nvoid stepThree();\nvoid waistBack();\nvoid stepBack();';
  Blockly.Arduino.definitions_['define_irevec'] ='\nint RECV_PIN = 5;\nint q = 1;\nint array_setup[] = {90,90,95};\nint angle1 = 25,angle2 = 35,angle3 = 55;\nint delayedTime1 = 5;\n';
  Blockly.Arduino.setups_['setup_sub_'] = 'pinMode(13,OUTPUT);\nmyservo1.attach(2);\nmyservo2.attach(3);\nmyservo3.attach(4);\n';
  var code = 'myservo1.attach(4);\nmyservo3.attach(2);\ndelayedTime1 = 3;\nwaistOne();\nstepOne();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistTwo();\nstepTwo();\nwaistThree();\nstepThree();\nwaistBack();\nstepBack();\ndelayedTime1 = 5;\ndelay(100);\n} \nwhile(1); \n}\nvoid waistOne()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] + angle1;\n}\nvoid stepOne()\n{\nfor(int i = 0;i < angle2;i++)\n{\n myservo1.write(array_setup[0] + i);\nmyservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + angle2;\narray_setup[2] = array_setup[2] - angle2;\n}\nvoid waistTwo()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n}\narray_setup[1] = array_setup[1] - 2*angle1;\n}\nvoid stepTwo()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - 2*angle2;\narray_setup[2] = array_setup[2] + 2*angle2;\n}\nvoid waistThree()\n{\nfor(int i = 0;i < 2*angle1;i++)\n{\nmyservo2.write(array_setup[1] + i);\ndelay(delayedTime1);\n}\n array_setup[1] = array_setup[1] + 2*angle1;\n}\nvoid stepThree()\n{\nfor(int i = 0;i < 2*angle2;i++)\n{\nmyservo1.write(array_setup[0] + i);myservo3.write(array_setup[2] - i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] + 2*angle2;\narray_setup[2] = array_setup[2] - 2*angle2;\n}\nvoid waistBack()\n{\nfor(int i = 0;i < angle1;i++)\n{\nmyservo2.write(array_setup[1] - i);\ndelay(delayedTime1);\n }\narray_setup[1] = array_setup[1] - angle1;\n}\nvoid stepBack()\n{\nfor(int i = 0;i < angle2;i++)\n{\nmyservo1.write(array_setup[0] - i);\nmyservo3.write(array_setup[2] + i);\ndelay(delayedTime1);\n}\narray_setup[0] = array_setup[0] - angle2;\narray_setup[2] = array_setup[2] + angle2;\nfor(int i=0;i<10;i++)\n{'; 
  return code;
};



Blockly.Arduino.lizard_move = function() {
  var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN',Blockly.Arduino.ORDER_ATOMIC);
  
  //value_degree = value_degree.replace('(','').replace(')','')
  
  //delay_time = delay_time.replace('(','').replace(')','');
  
  Blockly.Arduino.definitions_['define_servo'] = '#include <Servo.h>';
  Blockly.Arduino.definitions_['var_servo'+dropdown_pin] = 'Servo servo_'+dropdown_pin+';';
  Blockly.Arduino.setups_['setup_servo_'+dropdown_pin] = 'servo_'+dropdown_pin+'.attach('+dropdown_pin+');';
  
  var code = 'servo_'+dropdown_pin+'.write('+value_degree+');\n'+'delay(' + delay_time + ');\n';
  return code;
};












