2014-02-21 08:29:18 +08:00
|
|
|
# Leapmotion Arduino
|
|
|
|
|
|
|
|
First, let's import Cylon:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
var Cylon = require('../..');
|
|
|
|
|
2014-02-21 08:29:18 +08:00
|
|
|
Now that we have Cylon imported, we can start defining our robot
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
Cylon.robot({
|
2014-02-21 08:29:18 +08:00
|
|
|
|
|
|
|
Let's define the connections and devices:
|
|
|
|
|
|
|
|
connections: [
|
2014-11-07 07:57:16 +08:00
|
|
|
{ name: 'leapmotion', adaptor: 'leapmotion' },
|
2014-02-21 08:29:18 +08:00
|
|
|
{ name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
|
2014-03-27 08:06:26 +08:00
|
|
|
],
|
|
|
|
|
2014-02-21 08:29:18 +08:00
|
|
|
devices: [
|
|
|
|
{ name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' },
|
|
|
|
{ name: 'led', driver: 'led', pin: 13, connection: 'arduino' }
|
2014-03-27 08:06:26 +08:00
|
|
|
],
|
2014-02-21 08:29:18 +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:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
work: function(my) {
|
|
|
|
my.leapmotion.on('frame', function(frame) {
|
|
|
|
frame.hands.length > 0 ? my.led.turnOn() : my.led.turnOff();
|
|
|
|
});
|
|
|
|
}
|
2014-02-21 08:29:18 +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:
|
2014-03-27 08:06:26 +08:00
|
|
|
|
|
|
|
}).start();
|