2014-03-05 00:57:18 +08:00
|
|
|
var Cylon = require('../..');
|
|
|
|
|
|
|
|
Cylon.robot({
|
|
|
|
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyUSB0' },
|
2014-11-11 04:37:33 +08:00
|
|
|
devices: {
|
|
|
|
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;
|
|
|
|
|
|
|
|
every(1..seconds(), function() {
|
|
|
|
angle += increment;
|
|
|
|
my.servo.angle(angle);
|
|
|
|
|
|
|
|
console.log("Current Angle: " + (my.servo.currentAngle()));
|
|
|
|
|
|
|
|
if ((angle === 30) || (angle === 150)) { increment = -increment; }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).start();
|