-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (37 loc) · 1014 Bytes
/
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
//provision the gpio pins 22 for the led output and 17 for the button input
var ledToggle, pressCount;
//set the pin mode, setting pin 22 as an output and 17 as an input
var led = require("pi-pins").connect(22);
led.mode('out');
//set the initial value of the LED to be off.
led.value(false);
'use strict';
const express = require('express');
// Constants
const PORT = 80;
// App
const app = express();
app.get('/on', function (req, res) {
var led = require("pi-pins").connect(22);
led.mode('out');
led.value(true);
var start = new Date().getTime() / 1000;
var latertime = 5;
var leaveon = true
while (leaveon) {
var now = new Date().getTime() / 1000;
if (now - start >= latertime) {
leaveon = false;
led.value(false);
}
}
res.send('on\n');
});
app.get('/off', function (req, res) {
var led = require("pi-pins").connect(22);
led.mode('out');
led.value(false);
res.send('off\n');
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);