cylon/examples/rapiro/rapiro_servo.js

31 lines
614 B
JavaScript
Raw Normal View History

2014-12-14 08:19:25 +08:00
"use strict";
var Cylon = require("../..");
2014-03-05 00:57:18 +08:00
Cylon.robot({
2014-11-26 08:01:31 +08:00
connections: {
2014-12-14 08:19:25 +08:00
arduino: { adaptor: "firmata", port: "/dev/ttyUSB0" }
2014-11-26 08:01:31 +08:00
},
devices: {
2014-12-14 08:19:25 +08:00
led: { driver: "led", pin: 17 },
servo: { driver: "servo", pin: 2, range: { min: 30, max: 150 } }
},
2014-03-05 00:57:18 +08:00
work: function(my) {
my.led.turnOn();
var angle = 30;
var increment = 40;
2014-12-14 08:19:25 +08:00
every((1).seconds(), function() {
2014-03-05 00:57:18 +08:00
angle += increment;
my.servo.angle(angle);
console.log("Current Angle: " + (my.servo.currentAngle()));
if ((angle === 30) || (angle === 150)) { increment = -increment; }
});
}
}).start();