add led block
This commit is contained in:
parent
78f8bad4b3
commit
9a764b7e74
@ -4,13 +4,29 @@ import { getColour } from '../helpers/colour'
|
|||||||
import { selectedBoard } from '../helpers/board'
|
import { selectedBoard } from '../helpers/board'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Blockly.Blocks['sensebox_led'] = {
|
||||||
|
init: function () {
|
||||||
|
this.setColour(getColour().sensebox);
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField(Blockly.Msg.senseBox_led)
|
||||||
|
.appendField("Pin:")
|
||||||
|
.appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "PIN")
|
||||||
|
.appendField(Blockly.Msg.senseBox_basic_state)
|
||||||
|
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_on, "HIGH"], [Blockly.Msg.senseBox_off, "LOW"]]), "STAT");
|
||||||
|
this.setPreviousStatement(true, null);
|
||||||
|
this.setNextStatement(true, null);
|
||||||
|
this.setTooltip(Blockly.Msg.senseBox_led_tip);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Blockly.Blocks['sensebox_rgb_led'] = {
|
Blockly.Blocks['sensebox_rgb_led'] = {
|
||||||
init: function () {
|
init: function () {
|
||||||
this.setColour(getColour().sensebox);
|
this.setColour(getColour().sensebox);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(Blockly.Msg.senseBox_rgb_led)
|
.appendField(Blockly.Msg.senseBox_rgb_led)
|
||||||
.appendField("Pin:")
|
.appendField("Pin:")
|
||||||
.appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "PIN")
|
.appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "PIN");
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(Blockly.Msg.COLOUR_RGB_RED)//Blockly.Msg.senseBox_basic_red
|
.appendField(Blockly.Msg.COLOUR_RGB_RED)//Blockly.Msg.senseBox_basic_red
|
||||||
.appendField(new FieldSlider(255, 0, 255), "RED");
|
.appendField(new FieldSlider(255, 0, 255), "RED");
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import * as Blockly from 'blockly/core';
|
import * as Blockly from 'blockly/core';
|
||||||
import { Block } from 'blockly';
|
|
||||||
|
Blockly.Arduino.sensebox_led = function () {
|
||||||
|
var dropdown_pin = this.getFieldValue('PIN');
|
||||||
|
var dropdown_stat = this.getFieldValue('STAT');
|
||||||
|
Blockly.Arduino.setups_['setup_green_led_' + dropdown_pin] = 'pinMode(' + dropdown_pin + ', OUTPUT);';
|
||||||
|
var code = 'digitalWrite(' + dropdown_pin + ',' + dropdown_stat + ');\n'
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
Blockly.Arduino.sensebox_rgb_led = function () {
|
Blockly.Arduino.sensebox_rgb_led = function () {
|
||||||
var dropdown_pin = this.getFieldValue('PIN');
|
var dropdown_pin = this.getFieldValue('PIN');
|
||||||
|
@ -26,6 +26,7 @@ class Toolbox extends React.Component {
|
|||||||
</Category>
|
</Category>
|
||||||
<Category name="LED" colour={getColour().sensebox}>
|
<Category name="LED" colour={getColour().sensebox}>
|
||||||
<Block type="sensebox_rgb_led" />
|
<Block type="sensebox_rgb_led" />
|
||||||
|
<Block type="sensebox_led" />
|
||||||
</Category>
|
</Category>
|
||||||
<Category name="Display" colour={getColour().sensebox}>
|
<Category name="Display" colour={getColour().sensebox}>
|
||||||
<Block type="sensebox_display_beginDisplay" />
|
<Block type="sensebox_display_beginDisplay" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user