From f051992107dd069f40f168bd107a0d63b927f5a8 Mon Sep 17 00:00:00 2001
From: jordenvr <36641814+jordenvr@users.noreply.github.com>
Date: Thu, 29 Mar 2018 11:17:16 +0200
Subject: [PATCH 1/5] ledupblock changes
---
blockly/blocks/arduino/ledup_blocks.js | 46 ++++++++++++++++++++++
blockly/generators/arduino/ledup_blocks.js | 15 +++++++
2 files changed, 61 insertions(+)
diff --git a/blockly/blocks/arduino/ledup_blocks.js b/blockly/blocks/arduino/ledup_blocks.js
index 23baa86273..84109b1bee 100644
--- a/blockly/blocks/arduino/ledup_blocks.js
+++ b/blockly/blocks/arduino/ledup_blocks.js
@@ -133,3 +133,49 @@ Blockly.Blocks['ledupkidz_led_onoff'] = {
this.setTooltip(Blockly.Msg.ARD_LEDUP_LED_ONOFF_TIP);
}
};
+
+/**
+ * LEDUPKIDZ V2 blocks
+ *
+ */
+
+Blockly.Blocks['ledupkidzv2_digitalwrite'] = {
+ /**
+ * Block for setting led pin of ledupkidzv2 to a state.
+ * @this Blockly.Block
+ */
+ init: function() {
+ this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
+ this.setColour(Blockly.Blocks.light.HUE);
+ this.appendValueInput('STATE')
+ .appendField(Blockly.Msg.ARD_LEDLEG_SET)
+ .appendField(
+ new Blockly.FieldDropdown(
+ [['LED 1', '1'],
+ ['2', '2'],
+ ['3', '3'],
+ ['4', '4'],
+ ['5', '5'],
+ ['6', '6'],
+ ['7', '7'],
+ ]), 'LEDNAME')
+ .setCheck(Blockly.Types.BOOLEAN.checkList);
+ this.setInputsInline(false);
+ this.setPreviousStatement(true, 'ARD_BLOCK');
+ this.setNextStatement(true, 'ARD_BLOCK');
+ this.setTooltip(Blockly.Msg.ARD_DIGITALWRITE_TIP);
+ },
+ /**
+ * Called whenever anything on the workspace changes.
+ * It checks the instances of ledleg config and attaches a warning to this
+ * block if not valid data is found.
+ * @this Blockly.Block
+ */
+ onchange: function(event) {
+ if (!this.workspace || event.type == Blockly.Events.MOVE ||
+ event.type == Blockly.Events.UI) {
+ return; // Block deleted or irrelevant event
+ }
+
+ }
+};
diff --git a/blockly/generators/arduino/ledup_blocks.js b/blockly/generators/arduino/ledup_blocks.js
index 9c6e04af95..604fbe9719 100644
--- a/blockly/generators/arduino/ledup_blocks.js
+++ b/blockly/generators/arduino/ledup_blocks.js
@@ -135,3 +135,18 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
var code = 'set_ledupkidz_onoff(' + LEDNumber + ', ' + stateOutput + ');\n';
return code;
}
+
+/**
+ * LEDUPKIDZ V2 blocks
+ *
+ */
+
+/**
+ * Function for setting a specific LED of LedUpKidz to a state.
+ * @param {!Blockly.Block} block Block to generate the code from.
+ * @return {array} Completed code with order of operation.
+ */
+Blockly.Arduino['ledupkidzv2_digitalwrite'] = function(block) {
+ console.log(block);
+ return '';
+}
From 2e25fbcaeb708e6d70c05e02afd36314229b7c22 Mon Sep 17 00:00:00 2001
From: jordenvr <36641814+jordenvr@users.noreply.github.com>
Date: Thu, 29 Mar 2018 16:41:24 +0200
Subject: [PATCH 2/5] Hub voor ledup2
werkt nog niet, geeft meerdere errors
---
blockly/blocks/arduino/ledup_blocks.js | 107 ++++++++++++++++++---
blockly/generators/arduino/ledup_blocks.js | 56 ++++++++++-
blockly/index.html | 36 ++++++-
3 files changed, 182 insertions(+), 17 deletions(-)
diff --git a/blockly/blocks/arduino/ledup_blocks.js b/blockly/blocks/arduino/ledup_blocks.js
index 84109b1bee..3df21c206b 100644
--- a/blockly/blocks/arduino/ledup_blocks.js
+++ b/blockly/blocks/arduino/ledup_blocks.js
@@ -15,7 +15,7 @@ goog.provide('Blockly.Blocks.ledup_blocks');
goog.require('Blockly.Blocks');
-// The Hub block
+// The Hub block V1
Blockly.Blocks['ledup_hub'] = {
init: function() {
this.appendDummyInput()
@@ -139,26 +139,111 @@ Blockly.Blocks['ledupkidz_led_onoff'] = {
*
*/
-Blockly.Blocks['ledupkidzv2_digitalwrite'] = {
+// The Hub block V2
+Blockly.Blocks['ledup_hub_V2'] = {
+ init: function() {
+ this.appendDummyInput()
+ .appendField(Blockly.Msg.ARD_LEDUP_HUB);
+ this.appendDummyInput()
+ .setAlign(Blockly.ALIGN_RIGHT)
+ .appendField(new Blockly.FieldDropdown([
+ [Blockly.Msg.ARD_LEDUP_GADGET, "DEST_GADGET"], //For the attiny85 gadget
+ [Blockly.Msg.ARD_LEDUP_PROTO, "DEST_PROTOTYPE"], //For prototype on Arduino Uno
+ ]), "TARGET");
+ this.appendValueInput("LATCH")
+ .setCheck(["HUB_DIG", "HUB_DIGOUT"])
+ .setAlign(Blockly.ALIGN_RIGHT)
+ .appendField(Blockly.Msg.ARD_LEDUP_LED0);
+ this.appendValueInput("CLOCK")
+ .setCheck(["HUB_DIG", "HUB_DIGOUT"])
+ .setAlign(Blockly.ALIGN_RIGHT)
+ .appendField(Blockly.Msg.ARD_LEDUP_LED1);
+ this.appendValueInput("DATA")
+ .setCheck(["HUB_DIG", "HUB_DIGOUT"])
+ .setAlign(Blockly.ALIGN_RIGHT)
+ .appendField(Blockly.Msg.ARD_LEDUP_LED2);
+ this.setPreviousStatement(false, "MD_BLOCK");
+ this.setNextStatement(false, "MD_BLOCK");
+ this.setColour('#70D65C');
+ this.setTooltip(Blockly.Msg.ARD_LEDUP_HUB_TIP);
+ this.setHelpUrl('http://ingegno.be/01-blockly-4-arduino/');
+ },
+ /** @return {!boolean} True if the block instance is in the workspace. */
+ getLedUpKidzInstance: function() {
+ return true;
+ },
+ /**
+ * Returns the Arduino Board name that is required for this block.
+ * @return {!string} Board name.
+ * @this Blockly.Block
+ */
+ getBoardName: function() {
+ var target = this.getFieldValue('TARGET');
+ if (target == 'DEST_GADGET') {
+ return 'attiny85';
+ } else {
+ return 'uno'
+ }
+ },
+ /**
+ * Called whenever anything on the workspace changes.
+ * It checks if the board selected corresponds to what it should be
+ * block if not valid data is found.
+ * @this Blockly.Block
+ */
+ onchange: function(event) {
+ if (!this.workspace || event.type == Blockly.Events.MOVE ||
+ event.type == Blockly.Events.UI) {
+ return; // Block deleted or irrelevant event
+ }
+
+ // Iterate through top level blocks to find if there are other board modules
+ var blocks = this.workspace.getAllBlocks();
+ var otherBoardPresent = false;
+ for (var x = 0; x < blocks.length; x++) {
+ var func = blocks[x].getBoardName;
+ if (func) {
+ var BoardName = func.call(blocks[x]);
+ if (BoardName != this.getBoardName()) {
+ otherBoardPresent = true;
+ }
+ if (this != blocks[x]) {
+ // no two ledupkidx blocks allowed.
+ otherBoardPresent = true;
+ }
+ }
+ }
+
+ if (otherBoardPresent) {
+ // Set a warning to select a valid stepper config
+ this.setWarningText(Blockly.Msg.ARD_BOARD_WARN.replace('%1', Blockly.Msg.ARD_COMPONENT_BOARD), 'board');
+ } else {
+ Blockly.Arduino.Boards.changeBoard(this.workspace, this.getBoardName());
+ this.setWarningText(null, 'board');
+ }
+ },
+};
+
+
+Blockly.Blocks['ledupkidzv2_bitSet'] = {
/**
* Block for setting led pin of ledupkidzv2 to a state.
* @this Blockly.Block
*/
init: function() {
- this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
+ this.setHelpUrl('https://www.arduino.cc/en/Tutorial/ShiftOut');
this.setColour(Blockly.Blocks.light.HUE);
this.appendValueInput('STATE')
.appendField(Blockly.Msg.ARD_LEDLEG_SET)
.appendField(
new Blockly.FieldDropdown(
- [['LED 1', '1'],
- ['2', '2'],
- ['3', '3'],
- ['4', '4'],
- ['5', '5'],
- ['6', '6'],
- ['7', '7'],
- ]), 'LEDNAME')
+ [['1', '0'],
+ ['2', '1'],
+ ['3', '2'],
+ ['4', '3'],
+ ['5', '4'],
+ ['6', '5'],
+ ]), 'LEDNAME')
.setCheck(Blockly.Types.BOOLEAN.checkList);
this.setInputsInline(false);
this.setPreviousStatement(true, 'ARD_BLOCK');
diff --git a/blockly/generators/arduino/ledup_blocks.js b/blockly/generators/arduino/ledup_blocks.js
index 604fbe9719..ecbf3bdb0e 100644
--- a/blockly/generators/arduino/ledup_blocks.js
+++ b/blockly/generators/arduino/ledup_blocks.js
@@ -88,7 +88,6 @@ Blockly.Arduino['ledup_hub'] = function(block) {
return '';
};
-
/**
* Function for setting a specific LED of LedUpKidz to a state.
* @param {!Blockly.Block} block Block to generate the code from.
@@ -139,6 +138,7 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
/**
* LEDUPKIDZ V2 blocks
*
+ * Hub, bitset
*/
/**
@@ -146,7 +146,59 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
-Blockly.Arduino['ledupkidzv2_digitalwrite'] = function(block) {
+
+Blockly.Arduino['ledup_hub_V2'] = function(block) {
+
+ function parseInput(block, name, connectors) {
+ var targetBlock = block.getInputTargetBlock(name);
+ if (targetBlock) {
+ targetBlock.setHubConnector(connectors);
+ }
+ var code = Blockly.Arduino.blockToCode(targetBlock);
+ if (!goog.isString(code)) {
+ throw 'Expecting code from statement block "' + targetBlock.type + '".';
+ }
+ if (code) {
+ // blocks should only init data ...
+ console.log('Unexpected code in mcookie_hub', code);
+ }
+ return code;
+ }
+
+ var code = '';
+ var nr;
+
+ var target = block.getFieldValue('TARGET');
+
+ if (target == "DEST_PROTOTYPE") {
+ var blockinputs = [["latchPin", ['2']], ["clockPin", ['3']], ["dataPin", ['4']]];
+
+ code += '// Attiny wiring of the shift register\n' +
+ '/*' +
+ 'int latchPin = 1;\n' +
+ 'int clockPin = 0;n' +
+ 'int dataPin = 2;' +
+ '*/\n';
+ } else {
+ var blockinputs = [["latchPin", ['5']], ["clockPin", ['2']], ["dataPin", ['1']]];
+
+ code += '// Prototype wiring of the LED0 to 5\n' +
+ '/*' +
+ 'int latchPin = 11;\n' +
+ 'int clockPin = 10;n' +
+ 'int dataPin = 12;' +
+ '*/\n';
+ }
+ for (nr in blockinputs) {
+ parseInput(block, blockinputs[nr][0], blockinputs[nr][1]);
+ }
+
+ Blockly.Arduino.addInclude('ledupkidz', code);
+
+ return '';
+}
+
+Blockly.Arduino['ledupkidzv2_led_bitSet'] = function(block) {
console.log(block);
return '';
}
diff --git a/blockly/index.html b/blockly/index.html
index 00071e185c..9b1de4a834 100644
--- a/blockly/index.html
+++ b/blockly/index.html
@@ -14,12 +14,12 @@
-
+
-
+
@@ -873,7 +873,35 @@
+
+
+
+
+
+ TRUE
+
+
+
+
+
+ latchPin
+
+
+
+
+ clockPin
+
+
+
+
+ LED2
+
+
+
+
+
+
From af9e9ee02294d2a9cec2e4fe9120622dac83c924 Mon Sep 17 00:00:00 2001
From: jordenvr <36641814+jordenvr@users.noreply.github.com>
Date: Fri, 30 Mar 2018 09:18:17 +0200
Subject: [PATCH 3/5] ledup V2 hub
2 blocks in ledup V2, code achter het blok wordt weergegeven
---
blockly/blocks/arduino/ledup_blocks.js | 14 +++++------
blockly/generators/arduino/ledup_blocks.js | 18 +++++++-------
blockly/index.html | 28 +++++++++++-----------
blockly/msg/js/nl.js | 6 ++++-
4 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/blockly/blocks/arduino/ledup_blocks.js b/blockly/blocks/arduino/ledup_blocks.js
index 3df21c206b..8a30e9b613 100644
--- a/blockly/blocks/arduino/ledup_blocks.js
+++ b/blockly/blocks/arduino/ledup_blocks.js
@@ -143,25 +143,25 @@ Blockly.Blocks['ledupkidz_led_onoff'] = {
Blockly.Blocks['ledup_hub_V2'] = {
init: function() {
this.appendDummyInput()
- .appendField(Blockly.Msg.ARD_LEDUP_HUB);
+ .appendField(Blockly.Msg.ARD_LEDUP_HUB_V2);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.ARD_LEDUP_GADGET, "DEST_GADGET"], //For the attiny85 gadget
[Blockly.Msg.ARD_LEDUP_PROTO, "DEST_PROTOTYPE"], //For prototype on Arduino Uno
]), "TARGET");
- this.appendValueInput("LATCH")
+ this.appendValueInput("latchPin")
.setCheck(["HUB_DIG", "HUB_DIGOUT"])
.setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.ARD_LEDUP_LED0);
- this.appendValueInput("CLOCK")
+ .appendField(Blockly.Msg.LATCH);
+ this.appendValueInput("clockPin")
.setCheck(["HUB_DIG", "HUB_DIGOUT"])
.setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.ARD_LEDUP_LED1);
- this.appendValueInput("DATA")
+ .appendField(Blockly.Msg.CLOCK);
+ this.appendValueInput("dataPin")
.setCheck(["HUB_DIG", "HUB_DIGOUT"])
.setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.ARD_LEDUP_LED2);
+ .appendField(Blockly.Msg.DATA);
this.setPreviousStatement(false, "MD_BLOCK");
this.setNextStatement(false, "MD_BLOCK");
this.setColour('#70D65C');
diff --git a/blockly/generators/arduino/ledup_blocks.js b/blockly/generators/arduino/ledup_blocks.js
index ecbf3bdb0e..fea82c2dc4 100644
--- a/blockly/generators/arduino/ledup_blocks.js
+++ b/blockly/generators/arduino/ledup_blocks.js
@@ -171,22 +171,24 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
var target = block.getFieldValue('TARGET');
if (target == "DEST_PROTOTYPE") {
- var blockinputs = [["latchPin", ['2']], ["clockPin", ['3']], ["dataPin", ['4']]];
+ var blockinputs = [["latchPin", ['11']], ["clockPin", ['12']], ["dataPin", ['10']] ];
code += '// Attiny wiring of the shift register\n' +
'/*' +
'int latchPin = 1;\n' +
- 'int clockPin = 0;n' +
- 'int dataPin = 2;' +
+ 'int clockPin = 2;\n' +
+ 'int dataPin = 0;\n' +
+ 'byte register = 0;'
'*/\n';
} else {
- var blockinputs = [["latchPin", ['5']], ["clockPin", ['2']], ["dataPin", ['1']]];
+ var blockinputs = [["latchPin", ['1']], ["clockPin", ['2']], ["dataPin", ['0']] ];
code += '// Prototype wiring of the LED0 to 5\n' +
'/*' +
'int latchPin = 11;\n' +
- 'int clockPin = 10;n' +
- 'int dataPin = 12;' +
+ 'int clockPin = 12;\n' +
+ 'int dataPin = 10;\n' +
+ 'byte register = 0;' +
'*/\n';
}
for (nr in blockinputs) {
@@ -199,6 +201,6 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
}
Blockly.Arduino['ledupkidzv2_led_bitSet'] = function(block) {
- console.log(block);
- return '';
+ //console.log(block);
+ //return '';
}
diff --git a/blockly/index.html b/blockly/index.html
index 9b1de4a834..d34f22ae94 100644
--- a/blockly/index.html
+++ b/blockly/index.html
@@ -874,32 +874,32 @@
-
-
-
-
- TRUE
-
-
-
+
+
latchPin
-
+
clockPin
-
+
- LED2
+ dataPin
-
+
+
+
+
+
+ TRUE
+
+
-
-
+
diff --git a/blockly/msg/js/nl.js b/blockly/msg/js/nl.js
index 4ef5b1bd6d..ad1e856de9 100644
--- a/blockly/msg/js/nl.js
+++ b/blockly/msg/js/nl.js
@@ -599,7 +599,8 @@ Blockly.Msg.ARD_LEDLEG_ON = "AAN";
Blockly.Msg.ARD_LEDLEG_SET = "Zet LED";
Blockly.Msg.ARD_LEDLEG_TIP = "Een LED licht, een van de beentjes (de positieve of de negatieve) is verbonden aan de Arduino. Kan AAN of UIT zijn.";
Blockly.Msg.ARD_LEDUP_GADGET = "Gadget LedUpKidz";
-Blockly.Msg.ARD_LEDUP_HUB = "LedUpKidz, bestemming: ";
+Blockly.Msg.ARD_LEDUP_HUB = "LedUpKidz V1, bestemming: ";
+Blockly.Msg.ARD_LEDUP_HUB_V2 = "LedUpKidz V2, bestemming: ";
Blockly.Msg.ARD_LEDUP_HUB_TIP = "LedUpKidz is een gadget met 6 LED die je kunt programmeren. Er is een groot prototype via een Arduino UNO, kies prototype voor code daarvoor bestemd. Het gadget werkt op een kleine attiny85 microchip, voor code die daarop werkt, kies bestemming gadget.";
Blockly.Msg.ARD_LEDUP_LED0 = "LED 0";
Blockly.Msg.ARD_LEDUP_LED1 = "LED 1";
@@ -823,6 +824,9 @@ Blockly.Msg.UPLOAD_CLICK_2 = " 1. klik op de Arduino tab";
Blockly.Msg.UPLOAD_CLICK_3 = " 2. selecteeer alle code, en copieer (CTRL+A en CTRL+C)";
Blockly.Msg.UPLOAD_CLICK_4 = " 3. In de Arduino IDE of online via een http://codebender.cc sketch, plak je gecopieerde code (CTRL+V)";
Blockly.Msg.UPLOAD_CLICK_5 = " 4. Laad de code op naar je geconnecteerde Arduino";
+Blockly.Msg.LATCH = "Latch";
+Blockly.Msg.CLOCK= "Clock";
+Blockly.Msg.DATA = "Data";
Blockly.Msg.ARD_CONTROLS_EFFECT_MSG_THEN = Blockly.Msg.CONTROLS_REPEAT_INPUT_DO;
Blockly.Msg.ARD_CONTROLS_EFFECT_IF_TITLE_IF = Blockly.Msg.ARD_CONTROLS_EFFECT_MSG_IF;
Blockly.Msg.ARD_CONTROLS_EFFECT_IF_TOOLTIP = Blockly.Msg.CONTROLS_IF_IF_TOOLTIP;
From baff14e960458d2df0b0392bc87dab55b9efd4db Mon Sep 17 00:00:00 2001
From: jordenvr <36641814+jordenvr@users.noreply.github.com>
Date: Fri, 30 Mar 2018 15:27:48 +0200
Subject: [PATCH 4/5] ledup_hub_V2
geen errors meer
---
blockly/arduino_compressed.js | 3 +-
blockly/blocks/arduino/ledup_blocks.js | 16 +-------
blockly/generators/arduino/ledup_blocks.js | 45 ++++++++++++++--------
blockly/index.html | 18 +--------
4 files changed, 34 insertions(+), 48 deletions(-)
diff --git a/blockly/arduino_compressed.js b/blockly/arduino_compressed.js
index 571943f3eb..21fcdf6eac 100644
--- a/blockly/arduino_compressed.js
+++ b/blockly/arduino_compressed.js
@@ -254,7 +254,8 @@ Blockly.Arduino.ledupkidz_led_onoff=function(a){var c=Blockly.Arduino.valueToCod
var g,h="if";if(f)for(g in d){e="LED"+d[g][1];var k=f.getInputTargetBlock(d[g][0]);k&&k.getVars&&(e=k.getVars()[0]);a+=" "+h+" (lednr == "+d[g][1]+" && state) { digitalWrite("+e+", "+e+"_ON);}\n";h="else if";a+=" "+h+" (lednr == "+d[g][1]+" && !state) { digitalWrite("+e+", !"+e+"_ON);}\n"}Blockly.Arduino.addDeclaration("ledupkidz_onoff",a+"}\n");return"set_ledupkidz_onoff("+c+", "+b+");\n"};Blockly.Arduino.map={};Blockly.Arduino.base_map=function(a){var c=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"DMAX",Blockly.Arduino.ORDER_ATOMIC)||"0";return["map("+c+", 0, 1024, 0, "+a+")",Blockly.Arduino.ORDER_NONE]};Blockly.Arduino.variables={};Blockly.Arduino.variables_get=function(a){return[Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.variables_set=function(a){var c=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_ASSIGNMENT)||"0";return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" = "+c+";\n"};
Blockly.Arduino.variables_set_type=function(a){var c=Blockly.Arduino.valueToCode(a,"VARIABLE_SETTYPE_INPUT",Blockly.Arduino.ORDER_ASSIGNMENT)||"0";return["("+Blockly.Arduino.getArduinoType_(Blockly.Types[a.getFieldValue("VARIABLE_SETTYPE_TYPE")])+")("+c+")",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.light={};function hexToRgb(a){return 0===a.lastIndexOf("rgb",0)?(a=a.substring(4,a.length-1).replace(/ /g,"").split(","),{r:parseInt(a[0],10),g:parseInt(a[1],10),b:parseInt(a[2],10)}):(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:{r:0,g:0,b:0}}
Blockly.Arduino.led_config_hub=function(a){var c=a.getFieldValue("LEDNAME"),b="HIGH";"neg"==a.getFieldValue("POLARITY")&&(b="LOW");var d=(a.connector||["0","1"])[0];Blockly.Arduino.reservePin(a,d,Blockly.Arduino.PinTypes.OUTPUT,"Digital Write to LED");Blockly.Arduino.addVariable(c,"int "+c+" = "+d+";\nboolean "+c+"_ON = "+b+";",!0);Blockly.Arduino.addSetup("io_"+c,"pinMode("+c+", OUTPUT);",!1);return""};
-Blockly.Arduino.led_digitalwrite=function(a){var c=a.getFieldValue("LEDNAME");a=Blockly.Arduino.valueToCode(a,"STATE",Blockly.Arduino.ORDER_ATOMIC)||"LOW";return"digitalWrite("+c+", "+a+");\n"};Blockly.Arduino.led_digitalwrite_onoff=function(a){var c=a.getFieldValue("LEDNAME");a=a.getFieldValue("STATE");var b=c+"_ON";"off"==a&&(b="! ("+b+")");return"digitalWrite("+c+", "+b+");\n"};
+Blockly.Arduino.led_digitalwrite=function(a){var c=a.getFieldValue("LEDNAME");a=Blockly.Arduino.valueToCode(a,"STATE",Blockly.Arduino.ORDER_ATOMIC)||"LOW";return"digitalWrite("+c+", "+a+");\n"};
+Blockly.Arduino.led_digitalwrite_onoff=function(a){var c=a.getFieldValue("LEDNAME");a=a.getFieldValue("STATE");var b=c+"_ON";"off"==a&&(b="! ("+b+")");return"digitalWrite("+c+", "+b+");\n"};
Blockly.Arduino.neopixel_config_hub=function(a){var c=a.getFieldValue("LEDNAME"),b=Blockly.Arduino.valueToCode(a,"NUMBER",Blockly.Arduino.ORDER_ATOMIC)||"1",d=a.getFieldValue("KHZ"),e=a.getFieldValue("NEOPIXEL_TYPE"),f=(a.connector||["0","1"])[0];Blockly.Arduino.reservePin(a,f,Blockly.Arduino.PinTypes.OUTPUT,"Digital Write to Neopixel");Blockly.Arduino.addVariable(c,"int "+c+" = "+f+";",!0);a="myNeo_"+c;Blockly.Arduino.addDeclaration(a,"#include \nAdafruit_NeoPixel "+a+" = Adafruit_NeoPixel("+
b+", "+f+", "+e+" + "+d+");");Blockly.Arduino.addSetup("io_"+a,a+".begin();\n "+a+".show();",!1);return""};
Blockly.Arduino.neopixel_write=function(a){var c=a.getFieldValue("NEONAME"),b=Blockly.Arduino.valueToCode(a,"LEDPIXEL",Blockly.Arduino.ORDER_ATOMIC)||"0",d=Blockly.Arduino.valueToCode(a,"RED",Blockly.Arduino.ORDER_ATOMIC)||"255",e=Blockly.Arduino.valueToCode(a,"GREEN",Blockly.Arduino.ORDER_ATOMIC)||"255";a=Blockly.Arduino.valueToCode(a,"BLUE",Blockly.Arduino.ORDER_ATOMIC)||"255";return"myNeo_"+c+".setPixelColor("+b+"-1, myNeo_"+c+".Color("+d+","+e+","+a+"));\n"+("myNeo_"+c+".show();\n")};
diff --git a/blockly/blocks/arduino/ledup_blocks.js b/blockly/blocks/arduino/ledup_blocks.js
index 8a30e9b613..798077a746 100644
--- a/blockly/blocks/arduino/ledup_blocks.js
+++ b/blockly/blocks/arduino/ledup_blocks.js
@@ -149,22 +149,10 @@ Blockly.Blocks['ledup_hub_V2'] = {
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.ARD_LEDUP_GADGET, "DEST_GADGET"], //For the attiny85 gadget
[Blockly.Msg.ARD_LEDUP_PROTO, "DEST_PROTOTYPE"], //For prototype on Arduino Uno
- ]), "TARGET");
- this.appendValueInput("latchPin")
- .setCheck(["HUB_DIG", "HUB_DIGOUT"])
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.LATCH);
- this.appendValueInput("clockPin")
- .setCheck(["HUB_DIG", "HUB_DIGOUT"])
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.CLOCK);
- this.appendValueInput("dataPin")
- .setCheck(["HUB_DIG", "HUB_DIGOUT"])
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(Blockly.Msg.DATA);
+ ]), "TARGET");
this.setPreviousStatement(false, "MD_BLOCK");
this.setNextStatement(false, "MD_BLOCK");
- this.setColour('#70D65C');
+ this.setColour('#a54a59');
this.setTooltip(Blockly.Msg.ARD_LEDUP_HUB_TIP);
this.setHelpUrl('http://ingegno.be/01-blockly-4-arduino/');
},
diff --git a/blockly/generators/arduino/ledup_blocks.js b/blockly/generators/arduino/ledup_blocks.js
index fea82c2dc4..7c8fc4de37 100644
--- a/blockly/generators/arduino/ledup_blocks.js
+++ b/blockly/generators/arduino/ledup_blocks.js
@@ -149,7 +149,7 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
Blockly.Arduino['ledup_hub_V2'] = function(block) {
- function parseInput(block, name, connectors) {
+ /*function parseInput(block, name, connectors) {
var targetBlock = block.getInputTargetBlock(name);
if (targetBlock) {
targetBlock.setHubConnector(connectors);
@@ -163,8 +163,9 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
console.log('Unexpected code in mcookie_hub', code);
}
return code;
- }
+ }*/
+ var setfunc = 'void updateShiftRegister() {\n digitalWrite(latchPin, LOW);\n shiftOut(dataPin, clockPin, MSBFIRST, leds);\n digitalWrite(latchPin, HIGH);\n}';
var code = '';
var nr;
@@ -175,32 +176,44 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
code += '// Attiny wiring of the shift register\n' +
'/*' +
- 'int latchPin = 1;\n' +
- 'int clockPin = 2;\n' +
'int dataPin = 0;\n' +
- 'byte register = 0;'
- '*/\n';
+ 'int latchPin = 1;\n' +
+ 'int clockPin = 2;\n' +
+ 'byte register = 0;' +
+ '*/\n\n\n'+
+ '// Prototype wiring of the shift register\n' +
+ 'int dataPin = 10;\n' +
+ 'int latchPin = 11;\n' +
+ 'int clockPin = 12;\n' +
+ 'byte register = 0;' +
+ '\n';
+
} else {
var blockinputs = [["latchPin", ['1']], ["clockPin", ['2']], ["dataPin", ['0']] ];
- code += '// Prototype wiring of the LED0 to 5\n' +
+ code += '// Prototype wiring of the shift register\n' +
'/*' +
- 'int latchPin = 11;\n' +
- 'int clockPin = 12;\n' +
'int dataPin = 10;\n' +
+ 'int latchPin = 11;\n' +
+ 'int clockPin = 12;\n' +
'byte register = 0;' +
- '*/\n';
- }
- for (nr in blockinputs) {
- parseInput(block, blockinputs[nr][0], blockinputs[nr][1]);
+ '*/\n\n\n' +
+ '// Attiny wiring of the shift register\n' +
+ 'int dataPin = 0;\n' +
+ 'int latchPin = 1;\n' +
+ 'int clockPin = 2;\n' +
+ 'byte register = 0;' +
+ '\n';
}
-
- Blockly.Arduino.addInclude('ledupkidz', code);
+
+ Blockly.Arduino.addInclude('ledupkidzV2', code);
+ Blockly.Arduino.addDeclaration('ledupkidz_bitSetFunction', setfunc);
+ Blockly.Arduino.addSetup('ledupkidzV2', 'pinMode(latchPin, OUTPUT);\n pinMode(clockPin, OUTPUT);\n pinMode(dataPin, OUTPUT);\n register=0;\n updateShiftRegister();', false);
return '';
}
Blockly.Arduino['ledupkidzv2_led_bitSet'] = function(block) {
//console.log(block);
- //return '';
+ return '';
}
diff --git a/blockly/index.html b/blockly/index.html
index d34f22ae94..f83b35f169 100644
--- a/blockly/index.html
+++ b/blockly/index.html
@@ -875,23 +875,7 @@
-
-
-
- latchPin
-
-
-
-
- clockPin
-
-
-
-
- dataPin
-
-
-
+
From eddbdbeb2b9451ae297ca506229f37bef81ab483 Mon Sep 17 00:00:00 2001
From: jordenvr <36641814+jordenvr@users.noreply.github.com>
Date: Fri, 30 Mar 2018 16:56:22 +0200
Subject: [PATCH 5/5] blocks for ledupkidz v2
---
blockly/blocks/arduino/ledup_blocks.js | 2 +-
blockly/generators/arduino/ledup_blocks.js | 26 +++++++++++++++++-----
blockly/index.html | 8 +++----
3 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/blockly/blocks/arduino/ledup_blocks.js b/blockly/blocks/arduino/ledup_blocks.js
index 798077a746..3d4ebc5f3d 100644
--- a/blockly/blocks/arduino/ledup_blocks.js
+++ b/blockly/blocks/arduino/ledup_blocks.js
@@ -213,7 +213,7 @@ Blockly.Blocks['ledup_hub_V2'] = {
};
-Blockly.Blocks['ledupkidzv2_bitSet'] = {
+Blockly.Blocks['ledupkidzv2_bitSetClear'] = {
/**
* Block for setting led pin of ledupkidzv2 to a state.
* @this Blockly.Block
diff --git a/blockly/generators/arduino/ledup_blocks.js b/blockly/generators/arduino/ledup_blocks.js
index 7c8fc4de37..23a6f2a691 100644
--- a/blockly/generators/arduino/ledup_blocks.js
+++ b/blockly/generators/arduino/ledup_blocks.js
@@ -149,7 +149,7 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
Blockly.Arduino['ledup_hub_V2'] = function(block) {
- /*function parseInput(block, name, connectors) {
+ function parseInput(block, name, connectors) {
var targetBlock = block.getInputTargetBlock(name);
if (targetBlock) {
targetBlock.setHubConnector(connectors);
@@ -163,7 +163,7 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
console.log('Unexpected code in mcookie_hub', code);
}
return code;
- }*/
+ }
var setfunc = 'void updateShiftRegister() {\n digitalWrite(latchPin, LOW);\n shiftOut(dataPin, clockPin, MSBFIRST, leds);\n digitalWrite(latchPin, HIGH);\n}';
var code = '';
@@ -207,13 +207,27 @@ Blockly.Arduino['ledup_hub_V2'] = function(block) {
}
Blockly.Arduino.addInclude('ledupkidzV2', code);
- Blockly.Arduino.addDeclaration('ledupkidz_bitSetFunction', setfunc);
+ Blockly.Arduino.addDeclaration('ledupkidz_updateShiftRegister', setfunc);
Blockly.Arduino.addSetup('ledupkidzV2', 'pinMode(latchPin, OUTPUT);\n pinMode(clockPin, OUTPUT);\n pinMode(dataPin, OUTPUT);\n register=0;\n updateShiftRegister();', false);
return '';
}
-Blockly.Arduino['ledupkidzv2_led_bitSet'] = function(block) {
- //console.log(block);
- return '';
+Blockly.Arduino['ledupkidzv2_bitSetClear'] = function(block) {
+
+ var stateOutput = Blockly.Arduino.valueToCode(
+ block, 'STATE', Blockly.Arduino.ORDER_ATOMIC) || 'true';
+
+ var setfunc = 'void set_ledupkidz_bitSetClear {\n ';
+ var chosenLED = block.getFieldValue('LEDNAME');
+
+
+ var code = '';
+ if (stateOutput == 'true') {
+ code += 'bitSet(register, ' + chosenLED + ');\nupdateShiftRegister();';
+ } else {
+ code += 'bitClear(register, ' + chosenLED + ');\nupdateShiftRegister();';
+ }
+
+ return code;
}
diff --git a/blockly/index.html b/blockly/index.html
index f83b35f169..415656f2e3 100644
--- a/blockly/index.html
+++ b/blockly/index.html
@@ -872,11 +872,10 @@
-
-
+
-
+
TRUE
@@ -884,8 +883,7 @@
-
-
+