Skip to content

Instantly share code, notes, and snippets.

@hongkheng
Last active December 6, 2016 09:32
Show Gist options
  • Save hongkheng/bb13fd6e2a274d710fb40b486297d2c7 to your computer and use it in GitHub Desktop.
Save hongkheng/bb13fd6e2a274d710fb40b486297d2c7 to your computer and use it in GitHub Desktop.
cylon.js sweeping servo
/**
* Test script for testing a full sweep of a servo. This is to get the minimum and the maximum degree of the angle.
*/
Cylon.robot({
name: 'Servo1',
connections: {
arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' } // hard-coded serial port address
},
devices: {
servo: {
driver: 'servo',
pin: 9 // hard coded pin
}
},
work: function(my) {
var angle = 0;
var increment = 10;
console.log("safe angle given 0", my.servo.safeAngle(0));
console.log("safe angle given 180", my.servo.safeAngle(180));
console.log("Starting at angle", angle);
my.servo.angle(angle);
every((1).second(), function() {
angle += increment;
my.servo.angle(angle);
console.log("Current angle", my.servo.currentAngle());
// flip the increment
if ((angle === 0) || (angle === 180 )) {
increment = -increment;
}
});
}
}.start());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment