Using the Johnny-Five servos object

The Johnny-Five servos object is meant to help you group servos in ways that make sense for projects with many servos, such as hexapods with six legs, each containing multiple servos.

You can create a Servos object in a few different ways; the way we will use is to pass an array of constructed servo objects:

let servos = new five.Servos([servoOne, servoTwo])

This is where the magic happens—now that our servo objects are grouped in a Servos object, we can control them both independently and as a group:

servoOne.to(0) // Sets servoOne to 0 degrees
servoTwo.to(180) // Sets servoTwo to 180 degrees
servos.center() // Sets both servos to 90 degrees

And all servo object functions are available on the Servos object.

Let's add this to our code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.85.221