123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- 'use strict';
- goog.provide('Blockly.Blocks.basic101');
- goog.require('Blockly.Blocks');
- Blockly.Blocks.basic101.hue = 15;
- Blockly.Blocks['read_button'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_READBUTTON, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList,
- }]);
- this.setInputsInline(true);
- this.setOutput(true, Blockly.Types.BOOLEAN.output);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.BOOLEAN;
- }
- };
- Blockly.Blocks['basic101_dropdown_button'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["8", "8"],
- ["9", "9"],
- ["12", "12"],
- ["13", "13"]
- ]), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['read_knob'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_READKNOB, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList,
- }]);
- this.setInputsInline(true);
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_knob'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["A3", "A3"]
- ]), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['analog_light'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_SETANALOGLED, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList
- },
- {
- "type": "input_value",
- "name": "BRIGHTNESS",
- "check": Blockly.Types.NUMBER.checkList
- }
- ]);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip('');
- this.setHelpUrl('');
- },
- onchange: function() {
- var bright = Blockly.Python.valueToCode(this, "BRIGHTNESS", Blockly.Python.ORDER_ATOMIC)
- if (bright > 255 || bright < 0) {
- this.setWarningText(Blockly.Msg.BASIC_LIGHT_WARNING, 'light');
- } else {
- this.setWarningText(null, 'light');
- }
- },
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_analog_light'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["3", "3"],
- ["5", "5"],
- ["6", "6"],
- ]), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['digital_light'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_SETDIGITALLED, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList
- }]);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['basic101_dropdown_digital_light'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ]), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['nolight'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_NOLCD, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList
- }]);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip();
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['basic101_dropdown_nolight'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ]),
- 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['tone'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_SETTONE, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList
- },
- {
- "type": "input_value",
- "name": "FREQUENCY",
- "check": Blockly.Types.NUMBER.checkList
- }
- ]);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip(Blockly.Msg.BASIC_TONE_TIP);
- this.setHelpUrl('https://www.arduino.cc/en/Reference/tone');
- },
- onchange: function() {
- var freq = Blockly.Python.valueToCode(this, "FREQUENCY", Blockly.Python.ORDER_ATOMIC)
- if (freq < 31 || freq > 65535) {
- this.setWarningText(Blockly.Msg.BASIC_TONE_WARNING, 'io_tone');
- } else {
- this.setWarningText(null, 'io_tone');
- }
- },
- /** @return {!string} The type of input value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_tone'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["11", "11"]
- ]),
- 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['notone'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_NOTONE, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList
- }]);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip(Blockly.Msg.BASIC_NOTONE_TIP);
- this.setHelpUrl('https://www.arduino.cc/en/Reference/noTone');
- }
- };
- Blockly.Blocks['basic101_dropdown_notone'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["11", "11"]
- ]),
- 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_digital'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown(
- Blockly.Python.Boards.selected.digitalPins), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_analog'] = {
- /**
- * Block for creating a analog pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown(
- Blockly.Python.Boards.selected.analogPins), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_dropdown_pwm'] = {
- /**
- * Block for creating a analog pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown(
- Blockly.Python.Boards.selected.pwmPins), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['counter_button_setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_motorDriver.png", 140, 40, "15"));
- .appendField(new Blockly.FieldImage("./../blockly/media/main-sensor101-counter.png", 50, 40, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.BASIC_COUNTER_SETUP)
- this.appendDummyInput()
- .appendField(Blockly.Msg.BASIC_COUNTER_SETTING)
- .appendField(new Blockly.FieldDropdown(Blockly.Python.Boards.selected.digitalPins), 'PINSNUM');
- // this.interpolate_(Blockly.Msg.BASIC_COUNTER_SETUP, [
- // {
- // "type": "input_value",
- // "name": "PINSNUM",
- // "check": Blockly.Types.NUMBER.checkList,
- // }
- // ]);
- //this.setInputsInline(true);
- //this.setOutput(true, Blockly.Types.BOOLEAN.output);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['read_counter'] = {
- init: function() {
- this.interpolate_(Blockly.Msg.BASIC_READCOUNTER, [{
- "type": "input_value",
- "name": "PINSNUM",
- "check": Blockly.Types.NUMBER.checkList,
- }]);
- this.setInputsInline(true);
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.basic101.hue);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
- Blockly.Blocks['basic101_counter_dropdown_button'] = {
- /**
- * Block for creating a digtial pin selector.
- * @this Blockly.Block
- */
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["8", "8"],
- ["9", "9"],
- ]), 'SELECTPIN');
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(Blockly.Blocks.io.HUE);
- },
- /** @return {!string} The type of return value for the block, an integer. */
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- };
|