-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcheckInputs.js
executable file
·37 lines (32 loc) · 1017 Bytes
/
checkInputs.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
#!/usr/bin/env node
////////////////////////////////////////
// checkinputs.js
// Monitors all the predefined inputs.
// Wiring: Toggle the input you want to test.
// Setup:
// See:
////////////////////////////////////////
var b = require('bonescript');
var inputs = ["P8_9", "P8_10", "P8_11", "P8_12", "P8_15", "P8_16",
"P8_33", "P8_35", "P8_38",
"P9_11", "P9_17", "P9_18", "P9_19", "P9_20",
"P9_22", "P9_25", "P9_27", "P9_29", "P9_42"];
var states = [];
for(var i in inputs) {
b.pinMode(inputs[i], b.INPUT);
states[i] = 0;
}
setInterval(check, 100);
function check() {
var value;
// console.log("check");
for(var i in inputs) {
value = b.digitalRead(inputs[i]);
// console.log("value: ", value);
if(states[i] !== value) {
console.log(inputs[i], "changed to", value);
states[i] = value;
}
}
}
// Not working: "P8_15", "P8_33", "P8_35", "P8_38", "P9_11", "P9_22", "P9_25",