-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotion.js
41 lines (34 loc) · 1.09 KB
/
motion.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
var five = require("johnny-five");
var Raspi = require("raspi-io");
var board = new five.Board({
io: new Raspi()
});
let timerId = null;
board.on("ready", function() {
// Create a new `motion` hardware instance.
var motion = new five.Motion(2);
// "calibrated" occurs once, at the beginning of a session,
motion.on("calibrated", function() {
console.log("calibrated");
});
// "motionstart" events are fired when the "calibrated"
// proximal area is disrupted, generally by some form of movement
motion.on("motionstart", function() {
clearTimeout(timerId)
console.log("motionstart");
timerId = setTimeout(() => {
console.log('Timer ended!');
}, 30000);
});
// "motionend" events are fired following a "motionstart" event
// when no movement has occurred in X ms
motion.on("motionend", function() {
console.log("motionend");
});
// "data" events are fired at the interval set in opts.freq
// or every 25ms. Uncomment the following to see all
// motion detection readings.
// motion.on("data", function(data) {
// console.log(data);
// });
});