To get a servo working with Johnny-Five, we'll look at the Johnny-Five servo object, talk about wiring the servo to our PWM hat, and write our first piece of code to get the servo to sweep back and forth.
Looking at the servo page in the API section of the Johnny-Five documentation, we will look first for our constructor. Because we're still using the PCA9685 PWM hat, our constructor will look like this:
let servo = new five.Servo({ controller: "PCA9685", pin: 0 });
As for moving the servo, there are a few method described in the docs to move the servo. The first move can be to a fixed position:
servo.to(degree) servo.min() servo.max() servo.home() servo.center()
Or, another is to sweep back and forth, either as far back and forth as possible, or between a range:
servo.sweep() // goes 0-180 and back, then repeats servo.sweep(minDegree, maxDegree) // goes min to max and back, then repeats
You can also stop a moving servo...