-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (42 loc) · 873 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const gpio = require('onoff').Gpio
const red = new gpio(9, 'out')
const yellow = new gpio(10, 'out')
const green = new gpio(11, 'out')
const sleep = (howLong) => {
return new Promise((resolve) => {
setTimeout(resolve, howLong)
})
}
const runLights = async () => {
while (true) {
// Red
red.writeSync(1)
await sleep(3000)
// Red and Yellow
yellow.writeSync(1)
await sleep(1000)
// Green
red.writeSync(0)
yellow.writeSync(0)
green.writeSync(1)
await sleep(5000)
// Yellow
green.writeSync(0)
yellow.writeSync(1)
await sleep(2000)
// Yellow off
yellow.writeSync(0)
}
}
const allLightsOff = () => {
red.writeSync(0)
yellow.writeSync(0)
green.writeSync(0)
}
// Handle Ctrl+C exit cleanly
process.on('SIGINT', () => {
allLightsOff()
process.exit()
})
allLightsOff()
runLights()