Add cattoy example

This commit is contained in:
deadprogram 2014-02-18 20:33:10 -08:00
parent 1eb05c78fe
commit 308ffb7fad
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,29 @@
Cylon = require '../..'
Cylon.robot
connections: [
{name: 'digispark', adaptor: 'digispark'},
{name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437'}
]
devices: [
{name: 'servo1', driver: 'servo', pin: 0, connection: 'digispark'},
{name: 'servo2', driver: 'servo', pin: 1, connection: 'digispark'},
{name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion'}
]
work: (my) ->
my['x'] = 90
my['z'] = 90
my.leapmotion.on 'hand', (hand) ->
my['x'] = hand.palmX.fromScale(-300, 300).toScale(30, 150)
my['z'] = hand.palmZ.fromScale(-300, 300).toScale(30, 150)
every 100, ->
my.servo1.angle my['x']
my.servo2.angle my['z']
console.log "Current Angle: #{my.servo1.currentAngle()}, #{my.servo2.currentAngle()}"
.start()

31
examples/cattoy/cattoy.js Normal file
View File

@ -0,0 +1,31 @@
var Cylon = require('../..');
Cylon.robot({
connections: [
{ name: 'digispark', adaptor: 'digispark'},
{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' }
],
devices: [
{name: 'servo1', driver: 'servo', pin: 0, connection: 'digispark'},
{name: 'servo2', driver: 'servo', pin: 1, connection: 'digispark'},
{name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion'}
],
work: function(my) {
my['x'] = 90;
my['z'] = 90;
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);
});
every(100, function() {
my.servo1.angle(my['x']);
my.servo2.angle(my['z']);
console.log("Current Angle: " + my.servo1.currentAngle() + ", " + my.servo2.currentAngle());
});
}
}).start();