diff --git a/src/components/Blockly/blocks/loops.js b/src/components/Blockly/blocks/loops.js index 5986b3e..4dcf86a 100644 --- a/src/components/Blockly/blocks/loops.js +++ b/src/components/Blockly/blocks/loops.js @@ -1,53 +1,80 @@ import Blockly from 'blockly'; import { getColour } from '../helpers/colour'; +import { getCompatibleTypes } from '../helpers/types' -Blockly.defineBlocksWithJsonArray([ - { - type: 'controls_for', - message0: 'count with %1 from %2 to %3 by adding %4', - args0: [ - { - type: 'field_variable', - name: 'VAR', - variable: null, - variableTypes: ['Number'], - defaultType: 'Number', - createNewVariable: true, - showOnlyVariableAssigned: false, - }, - { - type: 'input_value', - name: 'FROM', - check: 'Number', - align: 'RIGHT', - }, - { - type: 'input_value', - name: 'TO', - check: 'Number', - align: 'RIGHT', - }, - { - type: 'input_value', - name: 'BY', - check: 'Number', - align: 'RIGHT', - }, - ], - message1: '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1', - args1: [ - { - type: 'input_statement', - name: 'DO', - }, - ], - inputsInline: false, - previousStatement: null, - nextStatement: null, - colour: getColour().loops, - helpUrl: '%{BKY_CONTROLS_FOR_HELPURL}', - extensions: ['contextMenu_newGetVariableBlock', 'controls_for_tooltip'], - }, -]); +// Blockly.defineBlocksWithJsonArray([ +// { +// type: 'controls_for', +// message0: 'count with %1 from %2 to %3 by adding %4', +// args0: [ +// { +// type: 'field_variable', +// name: 'VAR', +// variable: null, +// variableTypes: ['Number'], +// defaultType: 'Number', +// createNewVariable: true, +// showOnlyVariableAssigned: false, +// }, +// { +// type: 'input_value', +// name: 'FROM', +// check: 'Number', +// align: 'RIGHT', +// }, +// { +// type: 'input_value', +// name: 'TO', +// check: 'Number', +// align: 'RIGHT', +// }, +// { +// type: 'input_value', +// name: 'BY', +// check: 'Number', +// align: 'RIGHT', +// }, +// ], +// message1: '%{BKY_CONTROLS_REPEAT_INPUT_DO} %1', +// args1: [ +// { +// type: 'input_statement', +// name: 'DO', +// }, +// ], +// inputsInline: false, +// previousStatement: null, +// nextStatement: null, +// colour: getColour().loops, +// helpUrl: '%{BKY_CONTROLS_FOR_HELPURL}', +// extensions: ['contextMenu_newGetVariableBlock', 'controls_for_tooltip'], +// }, +// ]); + +Blockly.Blocks['controls_repeat_ext'] = { + /** + * Block for repeat n times (external number). + * @this Blockly.Block + */ + init: function () { + this.jsonInit({ + "message0": Blockly.Msg.CONTROLS_REPEAT_TITLE, + "args0": [ + { + "type": "input_value", + "name": "TIMES", + "check": getCompatibleTypes(Number), + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": getColour().loops, + "tooltip": Blockly.Msg.CONTROLS_REPEAT_TOOLTIP, + "helpUrl": Blockly.Msg.CONTROLS_REPEAT_HELPURL + }); + this.appendStatementInput('DO') + .appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO); + } +}; diff --git a/src/data/tutorials.json b/src/data/tutorials.json index 67f0384..4ba0518 100644 --- a/src/data/tutorials.json +++ b/src/data/tutorials.json @@ -1,90 +1,137 @@ [ - { - "id":1, - "title":"Erste Schritte", - "steps":[ - { - "id":1, - "type":"instruction", - "headline":"Erste Schritte", - "text":"In diesem Tutorial lernst du die ersten Schritte mit der senseBox kennen. Du erstellst ein erstes Programm, baust einen ersten Schaltkreis auf und lernst, wie du das Programm auf die senseBox MCU überträgst.", - "hardware":["senseboxmcu","led","breadboard","jst-adapter","resistor-470ohm"], - "requirements":[] - }, - { - "id":2, - "type":"instruction", - "headline":"Aufbau der Schaltung", - "text":"Stecke die LED auf das Breadboard und verbinde diese mithile des Widerstandes und dem JST Kabel mit dem Port Digital/Analog 1." - }, - { - "id":3, - "type":"instruction", - "headline":"Programmierung", - "text":"Jedes Programm für die senseBox besteht aus zwei Funktionen. Die Setup () Funktion wird zu Begin einmalig ausgeführt und der Programmcode Schrittweise ausgeführt. Nachdem die Setup () Funktion durchlaufen worden ist wird der Programmcode aus der zweiten Funktion, der Endlosschleife, fortlaufend wiederholt.", - "xml":"" - }, - { - "id":4, - "type":"instruction", - "headline":"Leuchten der LED", - "text":"Um nun die LED zum leuchten zu bringen wird folgender Block in die Endlosschleife eingefügt. Der Block bietet dir auszuwählen an welchen Pin die LED angeschlossen wurd und ob diese ein oder ausgeschaltet werden soll.", - "xml":"" - }, - { - "id":5, - "type":"task", - "headline":"Aufgabe 1", - "text":"Verwenden den Block zum leuchten der LED und übertrage dein erstes Programm auf die senseBox MCU.", - "xml":"" - } - ] - }, - { + { + "id": 1, + "title": "Erste Schritte", + "steps": [ + { + "id": 1, + "type": "instruction", + "headline": "Erste Schritte", + "text": "In diesem Tutorial lernst du die ersten Schritte mit der senseBox kennen. Du erstellst ein erstes Programm, baust einen ersten Schaltkreis auf und lernst, wie du das Programm auf die senseBox MCU überträgst.", + "hardware": [ + "senseboxmcu", + "led", + "breadboard", + "jst-adapter", + "resistor-470ohm" + ], + "requirements": [] + }, + { "id": 2, - "title": "WLAN einrichten", - "steps": [ - { - "id": 1, - "type": "instruction", - "headline": "Einführung", - "text": "In diesem Tutorial lernst du wie man die senseBox mit dem Internet verbindest.", - "hardware": ["senseboxmcu", "wifi-bee"], - "requirements": [1] - }, - { - "id": 2, - "type": "instruction", - "headline": "Programmierung", - "text": "Man benötigt folgenden Block:", - "media": { - "picture": "block_en.svg" - }, - "xml": "SSIDPassword" - }, - { - "id": 3, - "type": "instruction", - "headline": "Block richtig einbinden", - "text": "Dies ist ein Test.", - "media": { - "youtube": "sf3RzXq6iVo" - } - }, - { - "id": 4, - "type": "task", - "headline": "Aufgabe 1", - "text": "Stelle eine WLAN-Verbindung mit einem beliebigen Netzwerk her.", - "xml": "SSIDPassword" - }, - { - "id": 5, - "type": "task", - "headline": "Aufgabe 2", - "text": "Versuche das gleiche einfach nochmal. Übung macht den Meister! ;)", - "xml": "SSIDPassword" - } + "type": "instruction", + "headline": "Aufbau der Schaltung", + "text": "Stecke die LED auf das Breadboard und verbinde diese mithile des Widerstandes und dem JST Kabel mit dem Port Digital/Analog 1." + }, + { + "id": 3, + "type": "instruction", + "headline": "Programmierung", + "text": "Jedes Programm für die senseBox besteht aus zwei Funktionen. Die Setup () Funktion wird zu Begin einmalig ausgeführt und der Programmcode Schrittweise ausgeführt. Nachdem die Setup () Funktion durchlaufen worden ist wird der Programmcode aus der zweiten Funktion, der Endlosschleife, fortlaufend wiederholt.", + "xml": "" + }, + { + "id": 4, + "type": "instruction", + "headline": "Leuchten der LED", + "text": "Um nun die LED zum leuchten zu bringen wird folgender Block in die Endlosschleife eingefügt. Der Block bietet dir auszuwählen an welchen Pin die LED angeschlossen wurd und ob diese ein oder ausgeschaltet werden soll.", + "xml": "" + }, + { + "id": 5, + "type": "task", + "headline": "Aufgabe 1", + "text": "Verwenden den Block zum leuchten der LED und übertrage dein erstes Programm auf die senseBox MCU.", + "xml": "" + } + ] + }, + { + "id": 2, + "title": "Schleifen", + "steps": [ + { + "id": 1, + "type": "instruction", + "headline": "Schleifen", + "text": "In diesem Tutorial wird die Verwendung von Schleifen eingeführt. Eine Schleife (auch „Wiederholung“ oder englisch loop) ist eine Kontrollstruktur in Programmiersprachen. Sie wiederholt einen Anweisungs-Block – den sogenannten Schleifenrumpf oder Schleifenkörper –, solange die Schleifenbedingung als Laufbedingung gültig bleibt bzw. als Abbruchbedingung nicht eintritt. Schleifen, deren Schleifenbedingung immer zur Fortsetzung führt oder die keine Schleifenbedingung haben, sind Endlosschleifen. Die Endlosschleife hast du bereits im ersten Tutorial \"Erste Schritte\" kennengelernt", + "hardware": [ + "breadboard", + "jst-adapter", + "senseboxmcu", + "led", + "resistor-470ohm" + ], + "requirements": [ + 1 ] - } -] + }, + { + "id": 2, + "type": "instruction", + "headline": "Verwendung von Schleifen", + "text": "Die Blöcke findest du in der Kategorie \"Schleifen\". Die einfachste Schleife, die du Verwenden kannst, ist der Block \"Wiederhole 10 mal\". Bei diesem Block kannst du die Blöcke, die eine bestimmte Zahl wiederholt werden soll einfach in den offenen Block abschnitt ziehen. ", + "xml": "\n \n \n \n 10\n \n \n \n" + }, + { + "id": 3, + "type": "task", + "headline": "Verwendung von Schleifen", + "text": "Lass die LED genau 5 mal in einem Abstand von 1000 Millisekunden blinken. Anschließend soll die LED ausgeschaltet werden. ", + "xml": "\n \n \n \n \n \n 5\n \n \n \n \n 1\n HIGH\n \n \n \n \n 1000\n \n \n \n \n 1\n LOW\n \n \n \n \n 1000\n \n \n \n \n \n \n \n \n \n \n \n \n \n" + } + ] + }, + { + "id": 3, + "title": "WLAN einrichten", + "steps": [ + { + "id": 1, + "type": "instruction", + "headline": "Einführung", + "text": "In diesem Tutorial lernst du wie man die senseBox mit dem Internet verbindest.", + "hardware": [ + "senseboxmcu", + "wifi-bee" + ], + "requirements": [ + 1 + ] + }, + { + "id": 2, + "type": "instruction", + "headline": "Programmierung", + "text": "Man benötigt folgenden Block:", + "media": { + "picture": "block_en.svg" + }, + "xml": "SSIDPassword" + }, + { + "id": 3, + "type": "instruction", + "headline": "Block richtig einbinden", + "text": "Dies ist ein Test.", + "media": { + "youtube": "sf3RzXq6iVo" + } + }, + { + "id": 4, + "type": "task", + "headline": "Aufgabe 1", + "text": "Stelle eine WLAN-Verbindung mit einem beliebigen Netzwerk her.", + "xml": "SSIDPassword" + }, + { + "id": 5, + "type": "task", + "headline": "Aufgabe 2", + "text": "Versuche das gleiche einfach nochmal. Übung macht den Meister! ;)", + "xml": "SSIDPassword" + } + ] + } +] \ No newline at end of file