@@ -428,6 +428,39 @@ Blockly.Python['coderbot_adv_stop'] = function(block) {
428428 return 'get_bot().stop()\n' ;
429429} ;
430430
431+ // servo
432+ Blockly . Blocks [ 'coderbot_move_servo' ] = {
433+ // Block for moving forward.
434+ init : function ( ) {
435+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Motor' ) ;
436+ this . setColour ( 40 ) ;
437+
438+ this . appendDummyInput ( )
439+ . appendField ( Blockly . Msg . CODERBOT_MOVE_SERVO )
440+ . appendField ( new Blockly . FieldDropdown ( [ [ Blockly . Msg . CODERBOT_MOVE_SERVO_1 , "0" ] ,
441+ [ Blockly . Msg . CODERBOT_MOVE_SERVO_2 , "1" ] ] ) , 'SERVO' ) ;
442+ this . appendValueInput ( 'ANGLE' )
443+ . setCheck ( 'Number' )
444+ . appendField ( Blockly . Msg . CODERBOT_MOVE_SERVO_ANGLE ) ;
445+ this . setInputsInline ( true ) ;
446+ // Assign 'this' to a variable for use in the tooltip closure below.
447+ var thisBlock = this ;
448+ this . setTooltip ( function ( ) {
449+ var mode = thisBlock . getFieldValue ( 'ACTION' ) ;
450+ return TOOLTIPS [ mode ] + Blockly . Msg . CODERBOT_MOVE_SERVO_TIP_TAIL ;
451+ } ) ;
452+ this . setPreviousStatement ( true ) ;
453+ this . setNextStatement ( true ) ;
454+ }
455+ } ;
456+
457+ Blockly . Python [ 'coderbot_move_servo' ] = function ( block ) {
458+ // Generate Python for servo control.
459+ var servo = block . getFieldValue ( 'SERVO' ) ;
460+ var angle = Blockly . Python . valueToCode ( block , 'ANGLE' , Blockly . Python . ORDER_NONE ) ;
461+ var code = "get_bot().servo(servo=" + servo + ", angle=" + angle + ")\n" ;
462+ return code ;
463+ } ;
431464
432465Blockly . Blocks [ 'coderbot_camera_photoTake' ] = {
433466 // Block for taking a picture.
0 commit comments