The Johnny-Five motor object
The motor object in Johnny-Five allows us to easily control our motors without having to worry about communicating with the hat via the Pi. Let's code a test setup with the REPL before coding our project, to make sure everything is working.
Create a new project
folder and, inside it, run the following:
npm init -y
And, create a file in the folder named motor-test.js
. Start by requiring in Johnny-Five and Raspi-IO, instantiating your board object, and creating a board.on('ready')
handler, as we usually do:
constRaspi=require('raspi-io') constfive=require('johnny-five') constboard=newfive.Board({ io:newRaspi() }) board.on('ready', () => { })
Â
Now, we're ready to set up our motor object, keeping in mind that we'll need to configure for our hat.
Constructors for our hat
If you are using the Adafruit hat, your constructor is as follows:
let motor = new five.Motor(five.Motor.SHIELD_CONFIGS.ADAFRUIT_V2.M1)
And if you're using the L293D hat, your constructor is as follows...