Added support for Arduino tone/notone

zeedee
Nick Johnson 7 years ago
parent 43b8b03dbc
commit 08b95d0b5f
  1. 8
      blockly/apps/blocklyduino/index.html
  2. 1
      blockly/arduino_compressed.js
  3. 826
      blockly/blockly_uncompressed.js
  4. 31
      blockly/blocks/base.js
  5. 2
      blockly/blocks_compressed.js
  6. 15
      blockly/generators/arduino/base.js

@ -376,6 +376,14 @@ function init() {
</block>
</value>
</block>
<block type="inout_tone">
<value name="NUM">
<block type="math_number">
<field name="NUM">440</field>
</block>
</value>
</block>
<block type="inout_notone"></block>
<block type="inout_buildin_led"></block>
</category>
<category name="Servo">

@ -12,6 +12,7 @@ Blockly.Arduino.scrub_=function(a,b){if(null===b)return"";var c="";if(!a.outputC
b+e};Blockly.Arduino.base={};Blockly.Arduino.base_delay=function(){return"delay("+(Blockly.Arduino.valueToCode(this,"DELAY_TIME",Blockly.Arduino.ORDER_ATOMIC)||"1000")+");\n"};Blockly.Arduino.base_map=function(){var a=Blockly.Arduino.valueToCode(this,"NUM",Blockly.Arduino.ORDER_NONE),b=Blockly.Arduino.valueToCode(this,"DMAX",Blockly.Arduino.ORDER_ATOMIC);return["map("+a+", 0, 1024, 0, "+b+")",Blockly.Arduino.ORDER_NONE]};
Blockly.Arduino.inout_buildin_led=function(){var a=this.getFieldValue("STAT");Blockly.Arduino.setups_.setup_output_13="pinMode(13, OUTPUT);";return"digitalWrite(13, "+a+");\n"};Blockly.Arduino.inout_digital_write=function(){var a=this.getFieldValue("PIN"),b=this.getFieldValue("STAT");Blockly.Arduino.setups_["setup_output_"+a]="pinMode("+a+", OUTPUT);";return"digitalWrite("+a+", "+b+");\n"};
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_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()"};

File diff suppressed because one or more lines are too long

@ -132,6 +132,37 @@ Blockly.Blocks['inout_analog_read'] = {
}
};
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(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, 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(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("Stop generating a tone on a pin");
}
};
Blockly.Blocks['inout_highlow'] = {
helpUrl: 'http://arduino.cc/en/Reference/Constants',
init: function() {

@ -27,6 +27,8 @@ Blockly.Blocks.inout_digital_write={helpUrl:"http://arduino.cc/en/Reference/Digi
Blockly.Blocks.inout_digital_read={helpUrl:"http://arduino.cc/en/Reference/DigitalRead",init:function(){this.setColour(230);this.appendDummyInput().appendField("DigitalRead PIN#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PIN");this.setOutput(!0,"Boolean");this.setTooltip("")}};
Blockly.Blocks.inout_analog_write={helpUrl:"http://arduino.cc/en/Reference/AnalogWrite",init:function(){this.setColour(230);this.appendDummyInput().appendField("AnalogWrite PIN#").appendField(new Blockly.FieldDropdown(profile["default"].analog),"PIN");this.appendValueInput("NUM","Number").appendField("value").setCheck("Number");this.setInputsInline(!0);this.setPreviousStatement(!0,null);this.setNextStatement(!0,null);this.setTooltip("Write analog value between 0 and 255 to a specific Port")}};
Blockly.Blocks.inout_analog_read={helpUrl:"http://arduino.cc/en/Reference/AnalogRead",init:function(){this.setColour(230);this.appendDummyInput().appendField("AnalogRead PIN#").appendField(new Blockly.FieldDropdown(profile["default"].analog),"PIN");this.setOutput(!0,"Number");this.setTooltip("Return value between 0 and 1024")}};
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")}};

@ -79,6 +79,21 @@ Blockly.Arduino.inout_analog_read = function() {
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
Blockly.Arduino.inout_tone = function() {
var dropdown_pin = this.getFieldValue("PIN");
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 = "tone(" + dropdown_pin + ", " + value_num + ");\n";
return code;
};
Blockly.Arduino.inout_notone = function() {
var dropdown_pin = this.getFieldValue("PIN");
Blockly.Arduino.setups_['setup_output'+dropdown_pin] = 'pinMode('+dropdown_pin+', OUTPUT);';
var code = "noTone(" + dropdown_pin + ");\n";
return code;
};
Blockly.Arduino.inout_highlow = function() {
// Boolean values HIGH and LOW.
var code = (this.getFieldValue('BOOL') == 'HIGH') ? 'HIGH' : 'LOW';

Loading…
Cancel
Save