-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 754 Bytes
/
index.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
'use strict'
var http = require('http')
var tessel = require('tessel')
var notify = require('./notify')
var gpio = tessel.port['GPIO']
var input = gpio.pin['A1']
var power = gpio.pin['G1']
var speaker = gpio.pin['G4']
setInterval(poll, 1000 * 60 * 60)
poll()
var server = http.createServer(function (req, res) {
try {
read(function (value) {
res.statusCode = 200
res.end(value)
})
} catch (err) {
res.statusCode = 500
res.end(err.message)
}
})
// server.listen(8080)
function read (cb) {
power.output(1)
setTimeout(function () {
var value = input.read()
power.output(0)
cb(value)
}, 10)
}
function poll () {
read(function (value) {
if (value <= 0.2) {
notify(speaker)
}
})
}