meta données pour cette page
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| en:archives:blockly_rduino:create_blocks [2026/09/26 23:36] – supprimée - modification externe (Date inconnue) 127.0.0.1 | en:archives:blockly_rduino:create_blocks [2026/09/26 23:36] (Version actuelle) – ↷ Page déplacée de en:blockly_rduino:create_blocks à en:archives:blockly_rduino:create_blocks sebcanet | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ===== To create new block, here is a simple way using Grove LED block as example: ===== | ||
| + | |||
| + | **1 - modify index.html, ** at the __end __ of file add categories and **name of blocks** you want to add in the Toolbox (//sidebar menu//) : | ||
| + | < | ||
| + | < | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | </ | ||
| + | < | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | </ | ||
| + | < | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | <block type=" | ||
| + | </ | ||
| + | < | ||
| + | <block type=" | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | The different block name will be used for the block declaration **and ** the function: //parts #**2** & **#3** //' | ||
| + | |||
| + | The name are reference inside the file (en.js ; fr.js ; es.js; etc) with the text that will be dispalyed, so it's the multilingual way: //part #**5** for// ' | ||
| + | |||
| + | **2 - define functions in a particular file '/ | ||
| + | < | ||
| + | Blockly.Arduino.grove_led = function() { | ||
| + | var dropdown_pin = Blockly.Arduino.valueToCode(this, | ||
| + | var dropdown_stat = this.getFieldValue(' | ||
| + | Blockly.Arduino.setups_[' | ||
| + | var code = ' | ||
| + | return code; | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | **3 - define blocks with the same name as function, in a specific file in '/ | ||
| + | |||
| + | < | ||
| + | Blockly.Blocks[' | ||
| + | init: function() { | ||
| + | this.setColour(190); | ||
| + | this.setHelpUrl(Blockly.Msg.GROVE_INOUT_LED_HELPURL); | ||
| + | this.appendDummyInput() | ||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT1) | ||
| + | .appendField(new Blockly.FieldImage(" | ||
| + | //picture in local storage seems to be better idea, in the same directory as in js block file definition | ||
| + | |||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT2) | ||
| + | .appendField(new Blockly.FieldDropdown(profile.default.digital), | ||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT3) | ||
| + | .appendField(new Blockly.FieldDropdown([[" | ||
| + | //you can also put FieldDropdown in Lang file | ||
| + | this.setPreviousStatement(true, | ||
| + | this.setNextStatement(true, | ||
| + | this.setTooltip(Blockly.Msg.GROVE_INOUT_LED_TOOLTIP); | ||
| + | } | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | {{: | ||
| + | |||
| + | **4****- add the name of this 2 file __up __ in ' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <link rel=" | ||
| + | <meta http-equiv=" | ||
| + | < | ||
| + | <script type=" | ||
| + | <script type=" | ||
| + | |||
| + | <script type=" | ||
| + | <script type=" | ||
| + | |||
| + | <script type=" | ||
| + | <script type=" | ||
| + | <script type=" | ||
| + | <script type=" | ||
| + | </ | ||
| + | |||
| + | **5 - at last translating** in different language file. | ||
| + | |||
| + | → <font inherit/ | ||
| + | < | ||
| + | var MSG = { | ||
| + | title: " | ||
| + | labelArduinoCard: | ||
| + | span_config: | ||
| + | span_delete: | ||
| + | span_saveXML:" | ||
| + | </ | ||
| + | |||
| + | → Then in **/ | ||
| + | < | ||
| + | Blockly.Msg.ARDUINO_SERIAL_PRINT_CONTENT = " | ||
| + | Blockly.Msg.ARDUINO_SERIAL_PRINT_TOOLTIP = " | ||
| + | |||
| + | Blockly.Msg.GROVE_INOUT_LED_HELPURL = " | ||
| + | Blockly.Msg.GROVE_INOUT_LED_INPUT1 = " | ||
| + | Blockly.Msg.GROVE_INOUT_LED_INPUT2 = "sur la broche Digital"; | ||
| + | Blockly.Msg.GROVE_INOUT_LED_INPUT3 = "à l' | ||
| + | Blockly.Msg.GROVE_INOUT_LED_TOOLTIP = " | ||
| + | </ | ||
| + | |||
| + | **6 - tweak !** | ||
| + | |||
| + | You could also change the way the block is created or displayed, example with this different version: | ||
| + | |||
| + | < | ||
| + | Blockly.Blocks[' | ||
| + | init: function() { | ||
| + | this.setColour(190); | ||
| + | this.setHelpUrl(Blockly.Msg.GROVE_INOUT_LED_HELPURL); | ||
| + | this.appendDummyInput() | ||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT1) | ||
| + | .appendField(new Blockly.FieldImage(" | ||
| + | this.appendValueInput(" | ||
| + | .setCheck(' | ||
| + | .setAlign(Blockly.ALIGN_RIGHT) | ||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT2); | ||
| + | // | ||
| + | this.appendDummyInput("" | ||
| + | .setAlign(Blockly.ALIGN_RIGHT) | ||
| + | .appendField(Blockly.Msg.GROVE_INOUT_LED_INPUT3) | ||
| + | .appendField(new Blockly.FieldDropdown([[" | ||
| + | this.setPreviousStatement(true, | ||
| + | this.setNextStatement(true, | ||
| + | this.setTooltip(Blockly.Msg.GROVE_INOUT_LED_TOOLTIP); | ||
| + | } | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | {{: | ||
| + | |||
| + | if you uncomment line '' | ||
| + | |||