docs/servo-sweep.md
Servo connected to pin 10. Requires servo on pin that supports PWM (usually denoted by ~).
Fritzing diagram: docs/breadboard/servo.fzz
Run this example from the command line with:
node eg/servo-sweep.js
const {Board, Servo} = require("johnny-five");
const board = new Board();
board.on("ready", () => {
const servo = new Servo({
pin: 10,
startAt: 90
});
let lap = 0;
servo.sweep().on("sweep:full", () => {
console.log(`lap ${++lap}`);
if (lap === 1) {
servo.sweep({
range: [40, 140],
step: 10
});
}
if (lap === 2) {
servo.sweep({
range: [60, 120],
step: 5
});
}
if (lap === 3) {
servo.sweep({
range: [80, 100],
step: 1
});
}
if (lap === 5) {
process.exit(0);
}
});
});
<!--remove-start-->
Copyright (c) 2012-2014 Rick Waldron [email protected] Licensed under the MIT license. Copyright (c) 2015-2020 The Johnny-Five Contributors Licensed under the MIT license.
<!--remove-end-->