add block for the button
This commit is contained in:
		
							parent
							
								
									5daa336a04
								
							
						
					
					
						commit
						4fc0f14aed
					
				| @ -55,11 +55,11 @@ class BlocklyWindow extends Component { | ||||
|           style={this.props.svg ? { height: 0 } : this.props.blocklyCSS} | ||||
|           readOnly={this.props.readOnly !== undefined ? this.props.readOnly : false} | ||||
|           trashcan={this.props.trashcan !== undefined ? this.props.trashcan : true} | ||||
|           renderer='zelos' | ||||
|           renderer='geras' | ||||
|           zoom={{ // https://developers.google.com/blockly/guides/configure/web/zoom
 | ||||
|             controls: this.props.zoomControls !== undefined ? this.props.zoomControls : true, | ||||
|             wheel: false, | ||||
|             startScale: 0.8, | ||||
|             startScale: 1, | ||||
|             maxScale: 3, | ||||
|             minScale: 0.3, | ||||
|             scaleSpeed: 1.2 | ||||
|  | ||||
| @ -280,5 +280,24 @@ Blockly.Blocks['sensebox_sensor_sound'] = { | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Button | ||||
|  *  | ||||
|  *  | ||||
|  */ | ||||
| 
 | ||||
| Blockly.Blocks['sensebox_button'] = { | ||||
|   init: function () { | ||||
|     this.appendDummyInput() | ||||
|       .appendField(Blockly.Msg.senseBox_button) | ||||
|       .appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_button_isPressed, "isPressed"], [Blockly.Msg.senseBox_button_wasPressed, "wasPressed"], [Blockly.Msg.senseBox_button_switch, "Switch"]]), "FUNCTION") | ||||
|       .appendField("Pin:") | ||||
|       .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPinsButton), "PIN"); | ||||
|     this.setOutput(true, Types.BOOLEAN.typeName); | ||||
|     this.setColour(getColour().sensebox); | ||||
|     this.setTooltip(Blockly.Msg.senseBox_button_tip); | ||||
|     this.setHelpUrl('https://sensebox.de/books'); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -226,3 +226,29 @@ Blockly.Arduino.sensebox_sensor_sound = function () { | ||||
|   var code = 'microphone.getValue()'; | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Button | ||||
|  *  | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| Blockly.Arduino.sensebox_button = function () { | ||||
|   var dropdown_pin = this.getFieldValue('PIN'); | ||||
|   var dropown_function = this.getFieldValue('FUNCTION'); | ||||
|   Blockly.Arduino.libraries_['library_senseBoxMCU'] = '#include "SenseBoxMCU.h"'; | ||||
|   Blockly.Arduino.definitions_['define_button' + dropdown_pin + ''] = 'Button button_' + dropdown_pin + '(' + dropdown_pin + ');'; | ||||
|   Blockly.Arduino.setupCode_['setup_button' + dropdown_pin + ''] = 'button_' + dropdown_pin + '.begin();'; | ||||
|   var code = ''; | ||||
|   if (dropown_function === 'isPressed') { | ||||
|     code = 'button_' + dropdown_pin + '.isPressed()'; | ||||
|   } | ||||
|   else if (dropown_function === 'Switch') { | ||||
|     code = 'button_' + dropdown_pin + '.getSwitch()'; | ||||
|   } | ||||
|   else if (dropown_function === 'wasPressed') { | ||||
|     code = 'button_' + dropdown_pin + '.wasPressed()'; | ||||
|   } | ||||
|   return [code, Blockly.Arduino.ORDER_ATOMIC]; | ||||
| }; | ||||
| @ -47,6 +47,7 @@ class Toolbox extends React.Component { | ||||
|                     <Block type="sensebox_sensor_bme680_bsec" /> | ||||
|                     <Block type="sensebox_sensor_ultrasonic_ranger" /> | ||||
|                     <Block type="sensebox_sensor_sound" /> | ||||
|                     <Block type="sensebox_button" /> | ||||
|                 </Category > | ||||
|                 <Category name="WIFI" colour={getColour().sensebox}> | ||||
|                     <Block type="sensebox_wifi" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user