Remove delay parameter from Servo block.

This parameter simply duplicates the delay block. I think it should be removed because:
 - It takes up just as much space as a delay block.
 - It's not always needed.
 - When it's not needed, it wastes space, and
 - It needlessly complicates sketches by adding extra parameters.
zeedee
Nick Johnson 7 years ago
parent cc30912a37
commit c3c8c8b755
  1. 5
      blockly/apps/blocklyduino/index.html
  2. 2
      blockly/arduino_compressed.js
  3. 856
      blockly/blockly_uncompressed.js
  4. 4
      blockly/blocks/base.js
  5. 4
      blockly/blocks_compressed.js
  6. 7
      blockly/generators/arduino/base.js

@ -401,11 +401,6 @@ function init() {
<field name="NUM">0</field>
</block>
</value>
<value name="DELAY_TIME">
<block type="math_number">
<field name="NUM">1000</field>
</block>
</value>
</block>
<block type="servo_read_degrees"></block>
</category>

@ -14,7 +14,7 @@ Blockly.Arduino.inout_buildin_led=function(){var a=this.getFieldValue("STAT");Bl
Blockly.Arduino.inout_digital_read=function(){var a=this.getFieldValue("PIN");Blockly.Arduino.setups_["setup_input_"+a]="pinMode("+a+", INPUT);";return["digitalRead("+a+")",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.inout_analog_write=function(){var a=this.getFieldValue("PIN"),b=Blockly.Arduino.valueToCode(this,"NUM",Blockly.Arduino.ORDER_ATOMIC);return"analogWrite("+a+", "+b+");\n"};Blockly.Arduino.inout_analog_read=function(){return["analogRead("+this.getFieldValue("PIN")+")",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.inout_tone=function(){var a=this.getFieldValue("PIN"),b=Blockly.Arduino.valueToCode(this,"NUM",Blockly.Arduino.ORDER_ATOMIC);Blockly.Arduino.setups_["setup_output"+a]="pinMode("+a+", OUTPUT);";return"tone("+a+", "+b+");\n"};Blockly.Arduino.inout_notone=function(){var a=this.getFieldValue("PIN");Blockly.Arduino.setups_["setup_output"+a]="pinMode("+a+", OUTPUT);";return"noTone("+a+");\n"};
Blockly.Arduino.inout_highlow=function(){return["HIGH"==this.getFieldValue("BOOL")?"HIGH":"LOW",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.servo_move=function(){var a=this.getFieldValue("PIN"),b=Blockly.Arduino.valueToCode(this,"DEGREE",Blockly.Arduino.ORDER_ATOMIC),c=Blockly.Arduino.valueToCode(this,"DELAY_TIME",Blockly.Arduino.ORDER_ATOMIC)||"1000";Blockly.Arduino.definitions_.define_servo="#include <Servo.h>\n";Blockly.Arduino.definitions_["var_servo"+a]="Servo servo_"+a+";\n";Blockly.Arduino.setups_["setup_servo_"+a]="servo_"+a+".attach("+a+");\n";return"servo_"+a+".write("+b+");\ndelay("+c+");\n"};
Blockly.Arduino.servo_move=function(){var a=this.getFieldValue("PIN"),b=Blockly.Arduino.valueToCode(this,"DEGREE",Blockly.Arduino.ORDER_ATOMIC);Blockly.Arduino.definitions_.define_servo="#include <Servo.h>\n";Blockly.Arduino.definitions_["var_servo"+a]="Servo servo_"+a+";\n";Blockly.Arduino.setups_["setup_servo_"+a]="servo_"+a+".attach("+a+");\n";return"servo_"+a+".write("+b+");\n"};
Blockly.Arduino.servo_read_degrees=function(){var a=this.getFieldValue("PIN");Blockly.Arduino.definitions_.define_servo="#include &lt;Servo.h&gt;\n";Blockly.Arduino.definitions_["var_servo"+a]="Servo servo_"+a+";\n";Blockly.Arduino.setups_["setup_servo_"+a]="servo_"+a+".attach("+a+");\n";return"servo_"+a+".read()"};
Blockly.Arduino.serial_print=function(){var a=Blockly.Arduino.valueToCode(this,"CONTENT",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.setups_["setup_serial_"+profile["default"].serial]="Serial.begin("+profile["default"].serial+");\n";return"Serial.println("+a+");\n"};Blockly.Arduino.loops={};
Blockly.Arduino.controls_for=function(){var a=Blockly.Arduino.variableDB_.getName(this.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),b=Blockly.Arduino.valueToCode(this,"FROM",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",c=Blockly.Arduino.valueToCode(this,"TO",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",d=Blockly.Arduino.statementToCode(this,"DO");Blockly.Arduino.INFINITE_LOOP_TRAP&&(d=Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+this.id+"'")+d);if(b.match(/^-?\d+(\.\d+)?$/)&&c.match(/^-?\d+(\.\d+)?$/))var e=

File diff suppressed because one or more lines are too long

@ -189,10 +189,6 @@ Blockly.Blocks['servo_move'] = {
.setCheck('Number')
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("Degree (0~180)");
this.appendValueInput("DELAY_TIME", 'Number')
.setCheck('Number')
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("Delay");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('move between 0~180 degree');

@ -30,8 +30,8 @@ Blockly.Blocks.inout_analog_read={helpUrl:"http://arduino.cc/en/Reference/Analog
Blockly.Blocks.inout_tone={helpUrl:"http://www.arduino.cc/en/Reference/Tone",init:function(){this.setColour(230);this.appendDummyInput().appendField("Tone PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.appendValueInput("NUM","Number").appendField("frequency").setCheck("Number");this.setInputsInline(!0);this.setPreviousStatement(!0,null);this.setNextStatement(!0,null);this.setTooltip("Generate audio tones on a pin")}};
Blockly.Blocks.inout_notone={helpUrl:"http://www.arduino.cc/en/Reference/NoTone",init:function(){this.setColour(230);this.appendDummyInput().appendField("No tone PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.setInputsInline(!0);this.setPreviousStatement(!0,null);this.setNextStatement(!0,null);this.setTooltip("Stop generating a tone on a pin")}};
Blockly.Blocks.inout_highlow={helpUrl:"http://arduino.cc/en/Reference/Constants",init:function(){this.setColour(230);this.appendDummyInput().appendField(new Blockly.FieldDropdown([["HIGH","HIGH"],["LOW","LOW"]]),"BOOL");this.setOutput(!0,"Boolean");this.setTooltip("")}};
Blockly.Blocks.servo_move={helpUrl:"http://www.arduino.cc/playground/ComponentLib/servo",init:function(){this.setColour(190);this.appendDummyInput().appendField("Servo").appendField(new Blockly.FieldImage("http://www.seeedstudio.com/depot/images/product/a991.jpg",64,64)).appendField("PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.appendValueInput("DEGREE","Number").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField("Degree (0~180)");this.appendValueInput("DELAY_TIME",
"Number").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField("Delay");this.setPreviousStatement(!0,null);this.setNextStatement(!0,null);this.setTooltip("move between 0~180 degree")}};
Blockly.Blocks.servo_move={helpUrl:"http://www.arduino.cc/playground/ComponentLib/servo",init:function(){this.setColour(190);this.appendDummyInput().appendField("Servo").appendField(new Blockly.FieldImage("http://www.seeedstudio.com/depot/images/product/a991.jpg",64,64)).appendField("PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.appendValueInput("DEGREE","Number").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField("Degree (0~180)");this.setPreviousStatement(!0,
null);this.setNextStatement(!0,null);this.setTooltip("move between 0~180 degree")}};
Blockly.Blocks.servo_read_degrees={helpUrl:"http://www.arduino.cc/playground/ComponentLib/servo",init:function(){this.setColour(190);this.appendDummyInput().appendField("Servo").appendField(new Blockly.FieldImage("http://www.seeedstudio.com/depot/images/product/a991.jpg",64,64)).appendField("PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.appendDummyInput().setAlign(Blockly.ALIGN_RIGHT).appendField("Read Degrees");this.setOutput(!0,"Number");this.setTooltip("return that degree with the last servo move.")}};
Blockly.Blocks.serial_print={helpUrl:"http://www.arduino.cc/en/Serial/Print",init:function(){this.setColour(230);this.appendValueInput("CONTENT","String").appendField("Serial Print");this.setPreviousStatement(!0,null);this.setNextStatement(!0,null);this.setTooltip("Prints data to the console/serial port as human-readable ASCII text.")}};
// Copyright 2012 Google Inc. Apache License 2.0

@ -112,24 +112,19 @@ void setup() {
void loop() {
servo_11.write(0);
delay(2000);
servo_11.write(150); //0~180
delay(2000);
}
*/
Blockly.Arduino.servo_move = function() {
var dropdown_pin = this.getFieldValue('PIN');
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) || '1000'
//delay_time = delay_time.replace('(','').replace(')','');
Blockly.Arduino.definitions_['define_servo'] = '#include <Servo.h>\n';
Blockly.Arduino.definitions_['var_servo' + dropdown_pin] = 'Servo servo_' + dropdown_pin + ';\n';
Blockly.Arduino.setups_['setup_servo_' + dropdown_pin] = 'servo_' + dropdown_pin + '.attach(' + dropdown_pin + ');\n';
var code = 'servo_' + dropdown_pin + '.write(' + value_degree + ');\n' + 'delay(' + delay_time + ');\n';
var code = 'servo_' + dropdown_pin + '.write(' + value_degree + ');\n';
return code;
};

Loading…
Cancel
Save