Skip to content

Instantly share code, notes, and snippets.

@iCodeForBananas
Created April 10, 2015 06:44
Show Gist options
  • Select an option

  • Save iCodeForBananas/fd61c8f7c03d6b1deea7 to your computer and use it in GitHub Desktop.

Select an option

Save iCodeForBananas/fd61c8f7c03d6b1deea7 to your computer and use it in GitHub Desktop.
var tessel = require('tessel');
var servolib = require('servo-pca9685');
var servo = servolib.use(tessel.port['A']);
var servoNumber = 2; // Plug your servo or motor controller into port 1
// Reenable the console
process.stdin.resume();
console.log('Type in numbers between 0.0 and 1.0 to command the servo.');
console.log('Values between 0.05 and 0.15 are probably safe for most devices,');
console.log('but be careful and work your way out slowly.');
servo.on('ready', function () {
// Start at a duty cycle of 10%
var duty = 0.25;
// Set the min and max duty cycle to 0% and 100%,
// respectively to give you the maximum flexibility
// and to eliminate math
servo.configure(servoNumber, 0.05, 0.12, function () {
// Move into the starting position
servo.move(servoNumber, 0);
//servo.move(servoNumber, duty);
// Enter command positions into the command line. Work
// your way outwards until the servo begins to stall
// (or the motor velocity remains constant). Note the
// max an min values and use them in this *physical*
// motor/controller channel's `configure` call.
// Once you configure the motor, arguments to `move` of
// 0 and 1 will correspond to the minimum and maximum
// PWM values given in the `configure` call, thereby
// allowing you to easily command the actuator through
// its full range of motion.
process.stdin.on('data', function (duty) {
duty = parseFloat(String(duty));
console.log('Setting command position:', duty);
servo.move(servoNumber, duty);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment