Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion blockly/arduino_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 120 additions & 1 deletion blockly/blocks/arduino/ledup_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -133,3 +133,122 @@ Blockly.Blocks['ledupkidz_led_onoff'] = {
this.setTooltip(Blockly.Msg.ARD_LEDUP_LED_ONOFF_TIP);
}
};

/**
* LEDUPKIDZ V2 blocks
*
*/

// The Hub block V2
Blockly.Blocks['ledup_hub_V2'] = {
init: function() {
this.appendDummyInput()
.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.setPreviousStatement(false, "MD_BLOCK");
this.setNextStatement(false, "MD_BLOCK");
this.setColour('#a54a59');
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_bitSetClear'] = {
/**
* Block for setting led pin of ledupkidzv2 to a state.
* @this Blockly.Block
*/
init: function() {
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(
[['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');
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
}

}
};
98 changes: 97 additions & 1 deletion blockly/generators/arduino/ledup_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -135,3 +134,100 @@ Blockly.Arduino['ledupkidz_led_onoff'] = function(block) {
var code = 'set_ledupkidz_onoff(' + LEDNumber + ', ' + stateOutput + ');\n';
return code;
}

/**
* LEDUPKIDZ V2 blocks
*
* Hub, bitset
*/

/**
* 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['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 setfunc = 'void updateShiftRegister() {\n digitalWrite(latchPin, LOW);\n shiftOut(dataPin, clockPin, MSBFIRST, leds);\n digitalWrite(latchPin, HIGH);\n}';
var code = '';
var nr;

var target = block.getFieldValue('TARGET');

if (target == "DEST_PROTOTYPE") {
var blockinputs = [["latchPin", ['11']], ["clockPin", ['12']], ["dataPin", ['10']] ];

code += '// Attiny wiring of the shift register\n' +
'/*' +
'int dataPin = 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 shift register\n' +
'/*' +
'int dataPin = 10;\n' +
'int latchPin = 11;\n' +
'int clockPin = 12;\n' +
'byte register = 0;' +
'*/\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('ledupkidzV2', code);
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_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;
}
22 changes: 16 additions & 6 deletions blockly/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<script src="libs/bootstrap/js/bootstrap.min.js"></script>

<link rel="shortcut icon" href="blockly4Arduino/favicon3.png"/>
<!-- Blockly4Arduino - These three files contain the compress version -->
<!-- Blockly4Arduino - These three files contain the compress version
<script src="blockly_compressed.js"></script>
<script src="blocks_compressed.js"></script>
<script src="arduino_compressed.js"></script>
<script src="arduino_compressed.js"></script>-->
<!-- To use the uncompressed version comment out the above and comment in the ones below -->
<!--script src="blockly_uncompressed.js"></script>
<script src="blockly_uncompressed.js"></script>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="blocks/logic.js"></script>
<script src="blocks/loops.js"></script>
Expand Down Expand Up @@ -89,7 +89,7 @@
<script src="generators/arduino/md_actuator.js"></script>
<script src="generators/arduino/md_audio.js"></script>
<script src="generators/arduino/md_light.js"></script>
<script src="generators/arduino/ledup_blocks.js"></script-->
<script src="generators/arduino/ledup_blocks.js"></script>

<!-- Default language js files, user selection appended to head on load -->
<script type="text/javascript" src="msg/js/nl.js"></script>
Expand Down Expand Up @@ -872,8 +872,18 @@
</block>
</value>
</block>
</category>
</category>
</category>
<category id="catLedUpBlocks2" name="LedUp V2">
<block type="ledup_hub_V2"></block>
<block type="ledupkidzv2_bitSetClear">
<value name="STATE">
<block type="logic_boolean">
<field name="BOOL">TRUE</field>
</block>
</value>
</block>
</category>
</category>
<category id="catAllBot" name="AllBot">
<category id="catAllBotBlocks" name="AllBot Blokken">
<block type="allbotservo_config_hub"></block>
Expand Down
6 changes: 5 additions & 1 deletion blockly/msg/js/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down