cylon/examples/cattoy/cattoy.markdown

47 lines
1.3 KiB
Markdown
Raw Normal View History

2014-02-21 01:50:43 +08:00
# Cattoy
First, let's import Cylon:
var Cylon = require('../..');
2014-02-21 01:50:43 +08:00
Now that we have Cylon imported, we can start defining our robot
Cylon.robot({
2014-02-21 01:50:43 +08:00
Let's define the connections and devices:
connections: [
{ name: 'digispark', adaptor: 'digispark'},
{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' }
],
2014-02-21 01:50:43 +08:00
devices: [
{name: 'servo1', driver: 'servo', pin: 0, connection: 'digispark'},
{name: 'servo2', driver: 'servo', pin: 1, connection: 'digispark'},
{name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion'}
],
2014-02-21 01:50:43 +08:00
Now that Cylon knows about the necessary hardware we're going to be using, we'll
tell it what work we want to do:
work: function(my) {
my['x'] = 90;
my['z'] = 90;
2014-02-21 01:50:43 +08:00
my.leapmotion.on('hand', function(hand) {
my['x'] = hand.palmX.fromScale(-300, 300).toScale(30, 150);
my['z'] = hand.palmZ.fromScale(-300, 300).toScale(30, 150);
});
2014-02-21 01:50:43 +08:00
every(100, function() {
my.servo1.angle(my['x']);
my.servo2.angle(my['z']);
2014-02-21 01:50:43 +08:00
console.log("Current Angle: " + my.servo1.currentAngle() + ", " + my.servo2.currentAngle());
});
2014-02-21 01:50:43 +08:00
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
}).start()