/
servo.js
56 lines (45 loc) · 960 Bytes
/
servo.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
var arduino = require('../'),
board, led, servo;
// Construct instances
board = new arduino.Board({
debug: true
});
led = new arduino.Led({
board: board,
pin: 13
});
servo = new arduino.Servo({
board: board,
pin: 9
});
// Once servo is attached:
// - "read"
// - log position
// - "aftersweep"
// - blink the led
// - read the position
// - detach the servo
// - "detached"
// - log detach message
//
// - execute full sweep
servo.on('attached', function(err) {
console.log('attached');
this.on('read', function(err, pos) {
console.log(pos);
});
this.on('detached', function(err) {
console.log('detached');
});
this.on('aftersweep', function(err) {
led.blink();
this.read();
this.detach();
});
this.sweep();
});
// To test, use the following:
// http://arduino.cc/en/uploads/Tutorial/sweep_BB.png
//
// More information:
// http://www.ladyada.net/learn/sensors/pir.html