Skip to content

Commit 9a58b33

Browse files
author
Ke, Mingze
committed
Added cathode rgbled
1 parent c0085ab commit 9a58b33

6 files changed

Lines changed: 62 additions & 0 deletions

File tree

blocks/msg/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Blockly.Msg.WEBDUINO_RELAY_PIN = "pin";
180180
Blockly.Msg.WEBDUINO_RELAY_SET_STATE = "set state";
181181

182182
Blockly.Msg.WEBDUINO_RGBLED = "RGB LED";
183+
Blockly.Msg.WEBDUINO_RGBLED_CATHODE = "RGB LED (CATHODE)";
183184
Blockly.Msg.WEBDUINO_RGBLED_RED = "Red";
184185
Blockly.Msg.WEBDUINO_RGBLED_GREEN = "Green";
185186
Blockly.Msg.WEBDUINO_RGBLED_BLUE = "Blue";

blocks/msg/zh-hant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Blockly.Msg.WEBDUINO_RELAY_SET_STATE = "設定狀態";
203203
// RGB
204204

205205
Blockly.Msg.WEBDUINO_RGBLED = "三色 LED";
206+
Blockly.Msg.WEBDUINO_RGBLED_CATHODE = "三色共陰 LED";
206207
Blockly.Msg.WEBDUINO_RGBLED_RED = "紅";
207208
Blockly.Msg.WEBDUINO_RGBLED_GREEN = "綠";
208209
Blockly.Msg.WEBDUINO_RGBLED_BLUE = "藍";

blocks/webduino.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,44 @@ Blockly.Blocks['rgbled_new'] = {
929929
}
930930
};
931931

932+
Blockly.Blocks['rgbled_new_cathode'] = {
933+
init: function () {
934+
this.appendDummyInput()
935+
.appendField(Blockly.Msg.WEBDUINO_RGBLED_CATHODE, "RGBLed")
936+
.appendField(Blockly.Msg.WEBDUINO_RGBLED_RED, "red")
937+
.appendField(new Blockly.FieldDropdown([
938+
["3", "3"],
939+
["5", "5"],
940+
["6", "6"],
941+
["9", "9"],
942+
["10", "10"],
943+
["11", "11"]
944+
]), "red_")
945+
.appendField(Blockly.Msg.WEBDUINO_RGBLED_GREEN, "green")
946+
.appendField(new Blockly.FieldDropdown([
947+
["3", "3"],
948+
["5", "5"],
949+
["6", "6"],
950+
["9", "9"],
951+
["10", "10"],
952+
["11", "11"]
953+
]), "green_")
954+
.appendField(Blockly.Msg.WEBDUINO_RGBLED_BLUE, "blue")
955+
.appendField(new Blockly.FieldDropdown([
956+
["3", "3"],
957+
["5", "5"],
958+
["6", "6"],
959+
["9", "9"],
960+
["10", "10"],
961+
["11", "11"]
962+
]), "blue_");
963+
this.setOutput(true);
964+
this.setColour(230);
965+
this.setTooltip('');
966+
this.setHelpUrl('http://www.example.com/');
967+
}
968+
};
969+
932970
Blockly.Blocks['rgbled_setcolor'] = {
933971
init: function () {
934972
this.appendValueInput("color_")

generators/webduino.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,13 @@ Blockly.JavaScript['rgbled_new'] = function (block) {
707707
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
708708
};
709709

710+
Blockly.JavaScript['rgbled_new_cathode'] = function (block) {
711+
var dropdown_red_ = block.getFieldValue('red_');
712+
var dropdown_green_ = block.getFieldValue('green_');
713+
var dropdown_blue_ = block.getFieldValue('blue_');
714+
var code = 'getRGBLedCathode(board, ' + dropdown_red_ + ', ' + dropdown_green_ + ', ' + dropdown_blue_ + ')';
715+
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
716+
};
710717

711718
Blockly.JavaScript['rgbled_setcolor'] = function (block) {
712719
var variable_rgbled_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('rgbled_'), Blockly.Variables.NAME_TYPE);

views/index.handlebars

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,16 @@
500500
</block>
501501
</value>
502502
</block>
503+
<block type="variables_set">
504+
<field name="VAR">rgbled</field>
505+
<value name="VALUE">
506+
<block type="rgbled_new_cathode">
507+
<field name="red_">6</field>
508+
<field name="green_">9</field>
509+
<field name="blue_">10</field>
510+
</block>
511+
</value>
512+
</block>
503513
<block type="rgbled_setcolor">
504514
<field name="rgbled_">rgbled</field>
505515
<value name="color_">

webduino-blockly.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
return new webduino.module.RGBLed(board, board.getDigitalPin(red), board.getDigitalPin(green), board.getDigitalPin(blue));
7474
}
7575

76+
function getRGBLedCathode(board, red, green, blue) {
77+
return new webduino.module.RGBLed(board, board.getDigitalPin(red), board.getDigitalPin(green), board.getDigitalPin(blue), webduino.module.RGBLed.COMMON_CATHODE);
78+
}
79+
7680
function getUltrasonic(board, trig, echo) {
7781
return new webduino.module.Ultrasonic(board, board.getDigitalPin(trig), board.getDigitalPin(echo));
7882
}
@@ -255,6 +259,7 @@
255259
scope.getLed = getLed;
256260
scope.getRelay = getRelay;
257261
scope.getRGBLed = getRGBLed;
262+
scope.getRGBLedCathode = getRGBLedCathode;
258263
scope.getUltrasonic = getUltrasonic;
259264
scope.getButton = getButton;
260265
scope.getPir = getPir;

0 commit comments

Comments
 (0)