-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
53 lines (43 loc) · 1.36 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
const express = require('express')
const five = require('johnny-five')
const app = express()
const port = 3000
app.listen(port, function() {
console.log(`listening on port:${port}`)
})
var board = new five.Board({
repl: true,
debug: true,
// port: "/dev/tty.usbmodem1441"
})
var stepper
board.on("ready", function() {
stepper = new five.Stepper({
type: five.Stepper.TYPE.DRIVER,
stepsPerRev: 200,
pins: [6,7]
})
})
app.get("/", function(req, res) {
res.json("POST to /swipe to start a swipe")
})
app.post("/swipe", function(req, res) {
setTimeout( function() {
var didComplete = false
if (!board) {
res.status(500).json("Error setting up the board. Please check and make sure everything is connected and plugged in.")
}
if (!stepper) {
res.status(500).json("Error setting up the stepper. Please check and make sure everything is connected and plugged in.")
}
setTimeout( function() {
if (!didComplete) {
res.status(500).json("The operation took too long to complete. Please check and make sure everything is connected and plugged in.")
}
}, 2000)
stepper.rpm(600).ccw().step(2000, function() {
didComplete = true
res.json("success")
})
}, 1000);
})