Dial controls Servo Motor

Control servo motor in accordance with potention meter.


Let’s use two parts this time.
Connect the potentiometer and the servo motor to an obniz.

The potention meter should be connected to 0,1,2 and servo motor to 3,4,5.


The program is simple as it is a combination of what we have seen already.
This is the full code.

<!-- HTML Example -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@3.3.0/obniz.js"></script>

<div id="obniz-debug"></div>
<h1>Dial To Servo</h1>

var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
  var meter = obniz.wired("Potentiometer", {pin0:0, pin1:1, pin2:2});
  var servo = obniz.wired("ServoMotor", {gnd:3, vcc:4, signal:5});
  meter.onchange = function(position) {
    servo.angle(position * 180);

After opening the HTML, the servo motor will move following the potentiometer.
Perhaps the servo motor will rotate towards the opposite direction from the potentiometer.
How would you change the direction of rotation? Please give it a thought.