Servo

Library for controlling servos

Install command

curl -o src/libs/servo.ts https://c2coder.github.io/Jaculus-libraries/data/servo/servo.ts

Basic usage

import { Servo } from "./libs/servo.js"

const SERVO_PIN = 35;
const TIMER = 1;
const CHANNEL = 3;
const servo = new Servo(SERVO_PIN, TIMER, CHANNEL);

servo.write(0);    // 0°
servo.write(512);  // 90°
servo.write(1023); // 180°

Multiple servos

import { Servo } from "./libs/servo.js"

const SERVO_PIN = 35;
const TIMER = 1;
const CHANNEL_1 = 3;
const CHANNEL_2 = 4;

const servo_1 = new Servo(SERVO_PIN, TIMER, CHANNEL_1);
const servo_2 = new Servo(SERVO_PIN, TIMER, CHANNEL_2);

servo_1.write(0);    // 0°
servo_2.write(0);    // 0°

servo_1.write(512);  // 90°
servo_2.write(512);  // 90°

servo_1.write(1023); // 180°
servo_2.write(1023); // 180°

Source code: