-
Notifications
You must be signed in to change notification settings - Fork 0
/
momexpress.js
96 lines (86 loc) · 2.27 KB
/
momexpress.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
var express = require('express');
var app = express();
var path = require('path');
var {Led, Board} = require('johnny-five');
var say = require('say')
var board = new Board();
app.use( express.static( __dirname + '/views' ));
var port = process.env.PORT || "8100";
app.use(express.json());
app.use(express.urlencoded({
extended: true
}))
board.on('ready', () => {
var led = new Led(13);
var in1 = new Led(8)
var in2 = new Led(9)
var in3 = new Led(10)
var in4 = new Led(11)
app.get("/", (req, res) => {
res.status(200).sendFile(path.join(__dirname+'/views/index.html'))
});
app.post("/direction", (req, res) => {
var direction = req.body.direction;
console.log(direction)
if(direction == 'forward'){
led.blink(1000);
in1.on();
in2.off();
in3.on();
in4.off();
res.status(200).json({
direction: direction
})
}
else if(direction == 'backward'){
led.blink(2000);
in1.off();
in2.on();
in3.off();
in4.on();
res.status(200).json({
direction: direction
})
}
else if(direction == 'stop'){
led.blink(10000);
in1.off();
in2.off();
in3.off();
in4.off();
res.status(200).json({
direction: direction
})
}
else if(direction == 'right'){
led.blink(500);
in1.on();
in2.off();
in3.off();
in4.on();
res.status(200).json({
direction: direction
})
}
else if(direction == 'left'){
led.blink(5000);
in1.off();
in2.on();
in3.on();
in4.off();
res.status(200).json({
direction: direction
})
}
});
app.post("/speak", (req, res) => {
var speech = req.body.speech;
say.speak(speech);
res.status(200).json({
success: true
})
})
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});
})