-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
119 lines (102 loc) · 2.45 KB
/
app.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Import libraries
const five = require("johnny-five");
const express = require('express');
const app = express();
const path = require('path');
const server = require('http').Server(app);
const io = require('socket.io')(server);
var count = 0;
var soundIsOkay;
// Initializing Objects
const board = new five.Board();
var bumper, led, handlebarsObject,currColor, ledOn;
app.use(express.static(path.join(__dirname, 'public')));
// Render index.html
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
server.listen(3000);
board.on("ready", function() {
bumper = new five.Button(4);
led = new five.Led(2);
piezo = new five.Piezo(8);
soundPlaying = false;
ledOn = false;
var proximity = new five.Proximity({
controller: "HCSR04",
pin: 7
});
bumper.on("press", function() {
if(!ledOn) {
io.sockets.emit('led');
piezo.play({
song: [
["E6", 1],
["C6", 1],
["E6", 1],
["C6", 1],
],
tempo: 100
})
led.on();
soundPlaying = true;
ledOn = true;
}
else {
io.sockets.emit('ledoff');
led.off();
soundPlaying = false;
ledOn = false;
}
});/*.on("release", function() {
io.sockets.emit('ledoff');
led.off();
soundPlaying = false;
});*/
var x = 0;
proximity.on("data", function() {
console.log("Proximity: ");
console.log(" cm : ", this.cm);
console.log(" in : ", this.in);
console.log("-----------------");
// Call Doctor at 20 to 30 cm
if (this.cm > 20 && this.cm <= 30 && !piezo.isPlaying && !soundPlaying) {
io.sockets.emit('calldoctor');
piezo.play({
song: [
["C6", 10],
],
tempo:100
});
}
// Took Medication at 10 to 20 cm
if (this.cm > 10 && this.cm <= 20 && !piezo.isPlaying && !soundPlaying) {
io.sockets.emit('tookmedication');
piezo.play({
song: [
["C6", 10],
],
tempo:100
});
}
// Answered Doctors Question at 0 to 10 cm
if (this.cm > 0 && this.cm <= 10 && !piezo.isPlaying && !soundPlaying) {
io.sockets.emit('answerdoctor');
piezo.play({
song: [
["C6", 10],
],
tempo:100
});
}
else if (this.cm > 30 && !soundPlaying) {
io.sockets.emit('soundoff');
piezo.play({
song: [
[null, 1 / 4],
],
tempo: 100
});
};
});
});