-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathirProximitySensor.js
74 lines (52 loc) · 1.55 KB
/
irProximitySensor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const Cylon = require('cylon');
const EventEmitter = require('events');
const util = require('util');
Cylon.robot({
name: 'servoBot',
connections: {
arduino: { adaptor: 'firmata', port: '/dev/cu.usbmodem1411' } // /dev/cu.usbmodem1411 /dev/cu.usbmodem1451
},
devices: {
servo3: { driver: 'servo', pin: 3 },
servo13: { driver: 'servo', pin: 13 },
sensor: { driver: 'ir-range-sensor', pin: 0, model: 'gp2y0a41sk0f' }
},
work: function(my) {
my.servo3.angle(90);
my.servo13.angle(45);
my.emitter = new MyEmitter();
my.emitter.on('pitch0', function(pitch) {
my.servo13.angle(my.servo13.safeAngle(( (180/Math.PI) * pitch )));
});
my.emitter.on('yaw0', function(yaw) {
my.servo3.angle(my.servo3.safeAngle(( (180/Math.PI) * yaw )));
});
Cylon.devices = my;
console.log("Servo Motors are active");
every((1).seconds(), function(){
var range = my.sensor.range();
console.log('Range ===>', range);
});
}
}).start();
Cylon.robot({
name: 'leapmotionRobot',
connections: {
leapmotion: { adaptor: "leapmotion" }
},
devices: {
leapmotion: { driver: "leapmotion" }
},
work: function(my) {
my.leapmotion.on('frame', function (frame) {
if (frame.hands.length > 0 && Cylon.devices) {
Cylon.devices.emitter.emit('pitch0', frame.hands[0].pitch());
Cylon.devices.emitter.emit('yaw0', (Math.PI/2 - frame.hands[0].yaw() ));
}
});
}
}).start();
function MyEmitter() {
EventEmitter.call(this);
}
util.inherits(MyEmitter, EventEmitter);