forked from mounvip1525/Pedometer101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 759 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
const express = require("express");
const app = express();
var SerialPort = require("serialport");
var arduinoCOMPort = "COM6";
var data = 0;
const port = 5000;
app.set('view engine', 'ejs');
app.use(express.static("public"))
var arduinoSerialPort = new SerialPort(arduinoCOMPort, {
baudRate: 9600,
});
arduinoSerialPort.on("open", function () {
console.log("Serial Port " + arduinoCOMPort + " is opened.");
});
function read() {
data = (arduinoSerialPort.read());
// console.log(decodeURIComponent(data));
}
app.get("/", function (request, response) {
console.log(data);
response.render("pedo",{ steps : data })
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
setInterval(read, 1000);