johnny-five
Version:
The JavaScript Arduino Programming Framework.
85 lines (69 loc) • 1.93 kB
JavaScript
var five = require("../lib/johnny-five.js");
five.Board().on("ready", function() {
console.log("Connected");
// Initialize the servo
var servo = new five.Servo(process.argv[2] || 10);
// Servo alternate constructor with options
/*
var servo = new five.Servo({
id: "MyServo", // User defined id
pin: 10, // Which pin is it attached to?
type: "standard", // Default: "standard". Use "continuous" for continuous rotation servos
range: [0,180], // Default: 0-180
fps: 100, // Used to calculate rate of movement between positions
isInverted: false, // Invert all specified positions
startAt: 90, // Immediately move to a degree
center: true, // overrides startAt if true and moves the servo to the center of the range
specs: { // Is it running at 5V or 3.3V?
speed: five.Servo.Continuous.speeds["@5.0V"]
}
});
*/
// Add servo to REPL (optional)
this.repl.inject({
servo: servo
});
// Servo API
// min()
//
// set the servo to the minimum degrees
// defaults to 0
//
// eg. servo.min();
// max()
//
// set the servo to the maximum degrees
// defaults to 180
//
// eg. servo.max();
// center()
//
// centers the servo to 90°
//
// servo.center();
// to( deg )
//
// Moves the servo to position by degrees
//
// servo.to( 90 );
// step( deg )
//
// Moves the servo step degrees relative to current position
//
// servo.step( -10 );
// sweep( obj )
//
// Perform a min-max cycling servo sweep (defaults to 0-180)
// optionally accepts an object of sweep settings:
// {
// lapse: time in milliseconds to wait between moves
// defaults to 500ms
// degrees: distance in degrees to move
// defaults to 10°
// }
//
servo.sweep();
});
// References
//
// http://servocity.com/html/hs-7980th_servo.html