-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjohnny.js
83 lines (67 loc) · 1.69 KB
/
johnny.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Johnny-Five
var five = require("johnny-five");
var board = new five.Board();
//Express
var express = require('express');
var app = express();
var server = app.listen(8012);
console.log('Servidor Express Iniciado');
var valorLeituraLuz = 0;
var temperatura = 0;
var rele = false;
app.get('/leSensorLuz', function(req, res){
console.log('Luminozidade: ' + valorLeituraLuz);
res.send(valorLeituraLuz.toString());
});
app.get('/temperatura', function(req, res){
console.log('temperatura: ' + temperatura);
res.send(temperatura.toString());
});
app.get('/pulse', function(req, res){
// Create a standard `led` component
// on a valid pwm pin
var led = new five.Led(11);
led.pulse();
setTimeout(function() {
// stop() terminates the interval
// off() shuts the led off
led.stop().off();
}, 10000);
res.send('ok');
});
app.get('/rele', function(req, res){
console.log('rele: ' + req.query.ligado);
rele = req.query.ligado;
res.send(rele.toString());
var relay = new five.Relay(7);
if (rele == 'true')
{
relay.on();
}
if (rele == 'false') {
relay.off();
}
});
board.on("ready", function () {
// Create a new `photoresistor` hardware instance.
photoresistor = new five.Sensor({
pin: "A14",
freq: 250
});
// "data" get the current reading from the photoresistor
photoresistor.on("data", function () {
valorLeituraLuz = this.value;
//console.log(this.value);
});
//Termometro
var thermometer = new five.Thermometer({
controller: "GROVE",
pin: "A12"
});
thermometer.on("data", function() {
if (temperatura === Math.round(this.celsius)) {
return;
}
temperatura = Math.round(this.celsius);
});
});