PageSourceSearch

https://cocomake7.github.io/cocoblockly/blockly/blocks/arduino/servo.js

js cocomake7.github.io collected 2026-10-03 08:48:52 UTC 2,611 bytes, 84 lines download raw bytes

1/**
2 * @license Licensed under the Apache License, Version 2.0 (the "License"):
3 *          http://www.apache.org/licenses/LICENSE-2.0
4 */
5
6/**
7 * @fileoverview Arduino blocks for the Servo library.
8 *     The Arduino Servo functions can be found in
9 *     http://arduino.cc/en/reference/servo
10 *
11 * TODO: Add angle selector instead of block input.
12 */
13'use strict';
14
15goog.provide('Blockly.Blocks.servo');
16
17goog.require('Blockly.Blocks');
18goog.require('Blockly.Types');
19
20
21/** Common HSV hue for all blocks in this category. */
22Blockly.Blocks.servo.HUE = 60;
23
24Blockly.Blocks['servo_write'] = {
25  /**
26   * Block for writing an angle value into a servo PWM pin.
27   * @this Blockly.Block
28   */
29  init: function() {
30    this.setHelpUrl('http://arduino.cc/en/Reference/ServoWrite');
31    this.setColour(Blockly.Blocks.servo.HUE);
32    this.appendDummyInput()
33        .appendField(Blockly.Msg.ARD_SERVO_WRITE)
34        .appendField(new Blockly.FieldDropdown(
35            Blockly.Arduino.Boards.selected.pwmPins), 'SERVO_PIN');
36    this.setInputsInline(false);
37    this.appendValueInput('SERVO_ANGLE')
38        .setCheck(Blockly.Types.NUMBER.checkList)
39        .appendField(Blockly.Msg.ARD_SERVO_WRITE_TO);
40    this.appendDummyInput()
41        .appendField(Blockly.Msg.ARD_SERVO_WRITE_DEG_180);
42    this.setInputsInline(true);
43    this.setPreviousStatement(true, null);
44    this.setNextStatement(true, null);
45    this.setTooltip(Blockly.Msg.ARD_SERVO_WRITE_TIP);
46  },
47  /**
48   * Updates the content of the the pin related fields.
49   * @this Blockly.Block
50   */
51  updateFields: function() {
52    Blockly.Arduino.Boards.refreshBlockFieldDropdown(
53        this, 'SERVO_PIN', 'pwmPins');
54  }
55};
56
57Blockly.Blocks['servo_read'] = {
58  /**
59   * Block for reading an angle value of a servo PWM pin.
60   * @this Blockly.Block
61   */
62  init: function() {
63    this.setHelpUrl('http://arduino.cc/en/Reference/ServoRead');
64    this.setColour(Blockly.Blocks.servo.HUE);
65    this.appendDummyInput()
66        .appendField(Blockly.Msg.ARD_SERVO_READ)
67        .appendField(new Blockly.FieldDropdown(
68            Blockly.Arduino.Boards.selected.pwmPins), 'SERVO_PIN');
69    this.setOutput(true, Blockly.Types.NUMBER.output);
70    this.setTooltip(Blockly.Msg.ARD_SERVO_READ_TIP);
71  },
72  /** @return {string} The type of return value for the block, an integer. */
73  getBlockType: function() {
74    return Blockly.Types.NUMBER;
75  },
76  /**
77   * Updates the content of the the pin related fields.
78   * @this Blockly.Block
79   */
80  updateFields: function() {
81    Blockly.Arduino.Boards.refreshBlockFieldDropdown(
82        this, 'SERVO_PIN', 'pwmPins');
83  }
84};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.