commit 9521d790b3758dc775bb015701f79031727b393b Author: Christophe VILA Date: Sat Mar 11 19:53:28 2023 +0100 Initial revision diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..18d30d5 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# gpio diff --git a/blink.js b/blink.js new file mode 100644 index 0000000..a5b9366 --- /dev/null +++ b/blink.js @@ -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) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..edadcbc --- /dev/null +++ b/package-lock.json @@ -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" + } + } + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..a3e8e95 --- /dev/null +++ b/server.js @@ -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/");