added blocks for simple stepper motor
This commit is contained in:
		
							parent
							
								
									ef72dc8033
								
							
						
					
					
						commit
						dd82781939
					
				| @ -6,6 +6,7 @@ import "./sensebox-telegram"; | |||||||
| import "./sensebox-osem"; | import "./sensebox-osem"; | ||||||
| import "./sensebox-web"; | import "./sensebox-web"; | ||||||
| import "./sensebox-display"; | import "./sensebox-display"; | ||||||
|  | import "./sensebox-motor"; | ||||||
| import "./sensebox-lora"; | import "./sensebox-lora"; | ||||||
| import "./sensebox-led"; | import "./sensebox-led"; | ||||||
| import "./sensebox-rtc"; | import "./sensebox-rtc"; | ||||||
|  | |||||||
							
								
								
									
										64
									
								
								src/components/Blockly/blocks/sensebox-motor.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/components/Blockly/blocks/sensebox-motor.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,64 @@ | |||||||
|  | import * as Blockly from "blockly/core"; | ||||||
|  | import { getColour } from "../helpers/colour"; | ||||||
|  | import * as Types from "../helpers/types"; | ||||||
|  | import { selectedBoard } from "../helpers/board"; | ||||||
|  | import { FieldSlider } from "@blockly/field-slider"; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Stepper Motor | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | Blockly.Blocks["sensebox_motors_beginStepperMotor"] = { | ||||||
|  |     init: function () { | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .appendField(Blockly.Msg.sensebox_motors_beginStepperMotor); | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .appendField(Blockly.Msg.sensebox_motors_beginStepperMotor_pins); | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .setAlign(Blockly.ALIGN_RIGHT) | ||||||
|  |             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "in1") | ||||||
|  |             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "in2") | ||||||
|  |             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "in3") | ||||||
|  |             .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPins), "in4"); | ||||||
|  |         this.setFieldValue("1", "in1"); | ||||||
|  |         this.setFieldValue("2", "in2"); | ||||||
|  |         this.setFieldValue("3", "in3"); | ||||||
|  |         this.setFieldValue("4", "in4"); | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .appendField(Blockly.Msg.sensebox_motors_beginStepperMotor_rpm) | ||||||
|  |             .appendField(new FieldSlider(10, 1, 15), "rpm"); | ||||||
|  |         this.setPreviousStatement(true, null); | ||||||
|  |         this.setNextStatement(true, null); | ||||||
|  |         this.setColour(getColour().sensebox); | ||||||
|  |         this.setTooltip(Blockly.Msg.sensebox_motors_beginStepperMotor_tooltip); | ||||||
|  |         this.setHelpUrl(Blockly.Msg.sensebox_motors_beginStepperMotor_helpurl); | ||||||
|  |     }, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | Blockly.Blocks["sensebox_motors_moveStepperMotor"] = { | ||||||
|  |     init: function () { | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .appendField(Blockly.Msg.sensebox_motors_moveStepperMotor); | ||||||
|  |         this.appendDummyInput() | ||||||
|  |             .appendField(Blockly.Msg.sensebox_motors_moveStepperMotor_step) | ||||||
|  |             .setAlign(Blockly.ALIGN_RIGHT) | ||||||
|  |             .appendField(new Blockly.FieldNumber(2048), "steps"); | ||||||
|  |         this.setPreviousStatement(true, null); | ||||||
|  |         this.setNextStatement(true, null); | ||||||
|  |         this.setColour(getColour().sensebox); | ||||||
|  |         this.setTooltip(Blockly.Msg.sensebox_motors_moveStepperMotor_tooltip); | ||||||
|  |         this.setHelpUrl(Blockly.Msg.sensebox_motors_moveStepperMotor_helpurl); | ||||||
|  |     }, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Servo Motor | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * DC Motor | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| @ -5,6 +5,7 @@ import "./sensebox-telegram"; | |||||||
| import "./sensebox-osem"; | import "./sensebox-osem"; | ||||||
| import "./sensebox-web"; | import "./sensebox-web"; | ||||||
| import "./sensebox-display"; | import "./sensebox-display"; | ||||||
|  | import "./sensebox-motor"; | ||||||
| import "./sensebox-lora"; | import "./sensebox-lora"; | ||||||
| import "./sensebox-led"; | import "./sensebox-led"; | ||||||
| import "./sensebox"; | import "./sensebox"; | ||||||
|  | |||||||
							
								
								
									
										24
									
								
								src/components/Blockly/generator/sensebox-motor.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/components/Blockly/generator/sensebox-motor.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | import * as Blockly from "blockly/core"; | ||||||
|  | 
 | ||||||
|  | /*Stepper Motor Blocks*/ | ||||||
|  | Blockly.Arduino.sensebox_motors_beginStepperMotor = function () { | ||||||
|  |     var in1 = this.getFieldValue("in1"); | ||||||
|  |     var in2 = this.getFieldValue("in2"); | ||||||
|  |     var in3 = this.getFieldValue("in3"); | ||||||
|  |     var in4 = this.getFieldValue("in4"); | ||||||
|  |     var rpm = this.getFieldValue("rpm"); | ||||||
|  |     Blockly.Arduino.libraries_["stepper_motor"] = "#include <Stepper.h>"; | ||||||
|  |     Blockly.Arduino.definitions_["define_stepper_motor"] = ` | ||||||
|  | #define SPU 2048 // steps per minute
 | ||||||
|  | Stepper stepper_motor(SPU, ${in1}, ${in2}, ${in3}, ${in4}); // stepper Motor`;
 | ||||||
|  |     Blockly.Arduino.setupCode_["sensebox_stepper_motor_begin"] = | ||||||
|  |         `Motor.setSpeed(${rpm}); // speed in rotations per minute`; | ||||||
|  |     var code = ""; | ||||||
|  |     return code; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | Blockly.Arduino.sensebox_motors_moveStepperMotor = function () { | ||||||
|  |     var steps = this.getFieldValue("steps"); | ||||||
|  |     var code = "stepper_motor.step(2048);  // 2048 steps correspond to one rotation"; | ||||||
|  |     return code; | ||||||
|  | }; | ||||||
| @ -8,6 +8,7 @@ import { MATH } from "./en/math"; | |||||||
| import { MQTT } from "./en/mqtt"; | import { MQTT } from "./en/mqtt"; | ||||||
| import { SENSEBOX } from "./en/sensebox"; | import { SENSEBOX } from "./en/sensebox"; | ||||||
| import { DISPLAY } from "./en/sensebox-display"; | import { DISPLAY } from "./en/sensebox-display"; | ||||||
|  | import { MOTORS } from "./en/sensebox-motors"; | ||||||
| import { LED } from "./en/sensebox-led"; | import { LED } from "./en/sensebox-led"; | ||||||
| import { LORA } from "./en/sensebox-lora"; | import { LORA } from "./en/sensebox-lora"; | ||||||
| import { OSEM } from "./en/sensebox-osem"; | import { OSEM } from "./en/sensebox-osem"; | ||||||
| @ -34,6 +35,7 @@ export const En = { | |||||||
|   ...MATH, |   ...MATH, | ||||||
|   ...MQTT, |   ...MQTT, | ||||||
|   ...DISPLAY, |   ...DISPLAY, | ||||||
|  |   ...MOTORS, | ||||||
|   ...LED, |   ...LED, | ||||||
|   ...LORA, |   ...LORA, | ||||||
|   ...OSEM, |   ...OSEM, | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								src/components/Blockly/msg/en/sensebox-motors.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/components/Blockly/msg/en/sensebox-motors.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | |||||||
|  | export const MOTORS = { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Motors | ||||||
|  |      */ | ||||||
|  | 
 | ||||||
|  |     sensebox_motors_beginStepperMotor: "Initialize Stepper Motor (28BYJ-48)", | ||||||
|  |     sensebox_motors_beginStepperMotor_rpm: "Rotations per Minute", | ||||||
|  |     sensebox_motors_beginStepperMotor_pins: "Input Pins", | ||||||
|  |     sensebox_motors_beginStepperMotor_tooltip: "TODO", | ||||||
|  |     sensebox_motors_beginStepperMotor_helpurl: "TODO", | ||||||
|  |     sensebox_motors_beginStepperMotor_step: "TODO", | ||||||
|  | 
 | ||||||
|  |     sensebox_motors_moveStepperMotor: "Move Stepper Motor (28BYJ-48)", | ||||||
|  |     sensebox_motors_moveStepperMotor_step: "Steps:", | ||||||
|  |     sensebox_motors_moveStepperMotor_tooltip: "TODO", | ||||||
|  |     sensebox_motors_moveStepperMotor_helpurl: "TODO", | ||||||
|  | } | ||||||
| @ -298,6 +298,12 @@ class Toolbox extends React.Component { | |||||||
|             </Value> |             </Value> | ||||||
|           </Block> |           </Block> | ||||||
|         </Category> |         </Category> | ||||||
|  |         <Category name="Motors" colour={getColour().sensebox}> | ||||||
|  |           <Block type="sensebox_motors_beginStepperMotor" /> | ||||||
|  |           <Block type="sensebox_motors_moveStepperMotor" /> | ||||||
|  |           <Block type="sensebox_motors_beginStepperMotor" /> | ||||||
|  |           <Block type="sensebox_motors_beginStepperMotor" /> | ||||||
|  |         </Category> | ||||||
|         {/* <Category name="Telegram" colour={getColour().sensebox}> |         {/* <Category name="Telegram" colour={getColour().sensebox}> | ||||||
|           <Block type="sensebox_telegram" /> |           <Block type="sensebox_telegram" /> | ||||||
|           <Block type="sensebox_telegram_do" /> |           <Block type="sensebox_telegram_do" /> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user