Reader small image

You're reading from  Learning JavaScript Robotics

Product typeBook
Published inNov 2015
Reading LevelIntermediate
Publisher
ISBN-139781785883347
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Kassandra Perch
Kassandra Perch
author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch

Right arrow

Creating a project with a motor and using the REPL


Grab your motor and board, and follow the diagram in the previous section to wire a motor. Let's use pin 6 for the signal pin, as shown in the preceding diagram.

What we're going to do in our code is create a Motor object and inject it into the REPL, so we can play around with it in the command line. Create a motor.js file and put in the following code:

var five = require('johnny-five');

var board = new five.Board();

board.on('ready', function(){

  var motor = new five.Motor({
    pin: 6
  });

  this.repl.inject({
    motor: motor
  });
});

Then, plug in your board and use the motor.js node to start the program.

Exploring the motor API

If we take a look at the documentation on the Johnny-Five website, there are a few things we can try here. First, let's turn our motor on at about half speed:

> motor.start(125);

The .start() method takes a value between 0 and 255. Sounds familiar? That's because these are the values we can assign to a PWM...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning JavaScript Robotics
Published in: Nov 2015Publisher: ISBN-13: 9781785883347

Author (1)

author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch