Initial revision

This commit is contained in:
Christophe VILA 2023-03-11 19:53:28 +01:00
commit 9521d790b3
5 changed files with 69 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

1
README.md Normal file
View File

@ -0,0 +1 @@
# gpio

28
blink.js Normal file
View File

@ -0,0 +1,28 @@
var rpio = require('rpio')
var ledOn = false
rpio.open(22, rpio.INPUT, rpio.PULL_DOWN)
rpio.open(18, rpio.OUTPUT, ledOn ? rpio.HIGH : rpio.LOW)
function blinkLED() {
console.log("blinkLED")
ledOn = !ledOn
rpio.write(18, ledOn ? rpio.HIGH : rpio.LOW)
}
var blinkInterval = setInterval(blinkLED, 250)
function endBlinkLED() {
rpio.write(18, rpio.LOW)
clearInterval(blinkInterval)
}
setTimeout(endBlinkLED, 1000)
function pushButton() {
var buttonPushed = rpio.read(22)
console.log("pushButton %d", buttonPushed)
rpio.write(18, buttonPushed > 0 ? rpio.HIGH : rpio.LOW)
}
rpio.poll(22, pushButton)

25
package-lock.json generated Normal file
View File

@ -0,0 +1,25 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"bindings": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz",
"integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw=="
},
"nan": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.7.0.tgz",
"integrity": "sha1-2Vv3IeyHfgjbJ27T/G63j5CDrUY="
},
"rpio": {
"version": "0.9.19",
"resolved": "https://registry.npmjs.org/rpio/-/rpio-0.9.19.tgz",
"integrity": "sha1-FxtsClVVuerq0xd5Lt2HMWil2Nw=",
"requires": {
"bindings": "1.3.0",
"nan": "2.7.0"
}
}
}
}

14
server.js Normal file
View File

@ -0,0 +1,14 @@
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8080, IP defaults to 0.0.0.0
server.listen(8080);
// Put a friendly message on the terminal
console.log("Server running at http://0.0.0.0:8080/");