Skip to content

Instantly share code, notes, and snippets.

@jadonk
Created May 14, 2014 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/8f1a254a804401d8f21f to your computer and use it in GitHub Desktop.
Save jadonk/8f1a254a804401d8f21f to your computer and use it in GitHub Desktop.
var b = require('bonescript');
var SERVO = 'P9_14';
var duty_min = 0.03;
var position = 0;
var increment = 0.01;
var scale = 0.090;
//b.pinMode(SERVO, b.OUTPUT);
updateDuty();
function updateDuty() {
var duty_cycle = (position*scale) + duty_min;
b.analogWrite(SERVO, duty_cycle, 60, scheduleNextUpdate);
}
function scheduleNextUpdate() {
setTimeout(doRead, 20);
}
function doRead() {
b.analogRead('P9_36', onRead);
}
function onRead(x) {
if(!x.err) {
position = x.value;
}
updateDuty();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment