-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathping.js
More file actions
31 lines (24 loc) · 714 Bytes
/
Copy pathping.js
File metadata and controls
31 lines (24 loc) · 714 Bytes
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
var arduino = require('../'),
board, ping;
board = new arduino.Board({
debug: false
});
ping = new arduino.Ping({
board: board,
pin: 7
});
// 'read' events fire approx ~50ms
ping.on('read', function(err) {
// Current sensor data stored in properties
// of this Ping instance:
//
// this.microseconds - time lapse from fire to read
// this.inches - calculated distance to object in inches
// this.centimeters - calculated distance to object in centimeters
console.log('Object is ~' + Math.round(this.inches) + ' inches from sensor');
});
// To test, use the following:
// http://arduino.cc/en/uploads/Tutorial/ping_bb.png
//
// More information:
// http://arduino.cc/en/Tutorial/Ping