-
Notifications
You must be signed in to change notification settings - Fork 33
/
reedSwitch.js
51 lines (45 loc) · 1.52 KB
/
reedSwitch.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
#!/usr/bin/node
/**
fireAlarm.js
Example firmata driver script with multiple inputs / outputs.
Used to listen to a flame sensor and trigger buzzer and LED on fire trigger.
Also includes button override to trigger events.
In addition we also use a reed switch to sense when a magnet is within proximity to trigger events.
When events are triggered, we use curl to post data to remote IP / PORT 192.168.1.81:9999, a SignagePlayer
LAN server gateway (replace with your IP address / port set in the SignageStudio).
**/
var firmata = require('firmata');
var exec = require('child_process').exec;
var _ = require('underscore');
var c = 0;
var board = new firmata.Board("/dev/ttyATH0", function (err) {
console.log('starting reed listening');
board.on('string', function (string) {
console.log('firmata log: ' + string);
});
if (err) {
console.log(err);
board.reset();
return;
}
var REED = 2;
var LEDPIN = 13;
function resetLED (){
setTimeout(function(){
board.digitalWrite(LEDPIN, board.LOW);
},4000)
}
board.pinMode(REED, board.MODES.INPUT);
board.pinMode(LEDPIN, board.MODES.OUTPUT);
board.digitalWrite(LEDPIN, board.LOW);
board.digitalRead(REED, _.debounce(function (e) {
if (e == 1) {
console.log('door triggered ' + c++ );
board.digitalWrite(LEDPIN, board.HIGH);
resetLED();
}
}, 500, true));
//board.digitalRead(REED, function (e) {
// console.log(e);
//});
});