Control Shieldbot with JavaScript
Must be done inside board ready
var five = require("johnny-five");
var Shieldbot = require('shieldbot');
var board = new five.Board();
board.on("ready", function(){
var shieldbot = new Shieldbot();
});
Returns a promise that is resolved after specified duration
// delay for 1000 milliseconds
shieldbot.wait(1000).then(function(){
// do something after delay
});
Typically used internally
// magnitude can be between -128 & 127
shieldbot.motor('leftPins', 127);
shieldbot.motor('rightPins', 127);
Typically used internally
// magnitude can be between -128 & 127
shieldbot.leftMotor(127);
Typically used internally
// magnitude can be between -128 & 127
shieldbot.rightMotor(127);
Given a speed and duration, drives the bot forward
Returns a promise that is resolved after specified duration
shieldbot.forward(127, 4800);
Given a speed and duration, drives the bot backward
Returns a promise that is resolved after specified duration
shieldbot.reverse(127, 4800);
Stops the bot
Returns a resolved promised
shieldbot.stop();
Typically used internally
shieldbot.fastStopSide('leftPins');
shieldbot.fastStopSide('rightPins');
You should probably be using stop
shieldbot.fastStop();
Given a speed and duration, turns the bot left
Returns a promise that is resolved after specified duration
shieldbot.turnLeft(127, 1000);
Given a speed and duration, turns the bot right
Returns a promise that is resolved after specified duration
shieldbot.turnRight(127, 1000);
The Shieldbot also has finders on the front (good for line following)
We emit events when the finder values change
Callbacks receive the pin number that changed
shieldbot.on('finder.on', function(pin){
console.log('on', pin);
});
shieldbot.on('finder.off', function(pin){
console.log('off', pin);
});