From f46517aeb0f88043367ee78a8503dd17447b5663 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Fri, 11 Sep 2020 12:42:13 +0100 Subject: [PATCH] initial commit --- app.js | 17 ++++++++++++++++ package-lock.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 app.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/app.js b/app.js new file mode 100644 index 0000000..04c22ed --- /dev/null +++ b/app.js @@ -0,0 +1,17 @@ +const { Gpio } = require( 'onoff' ); + +// set BCM 4 pin as 'output' +const ledOut = new Gpio( '4', 'out' ); + +// set BCM 17 pin as 'input' +const switchIn = new Gpio( '17', 'in', 'both' ); + +// listen for pin voltage change +switchIn.watch( ( err, value ) => { + if( err ) { + console.log( 'Error', err ); + } + + // write the input value (0 or 1) 'ledOut' pin + ledOut.writeSync( value ); +} ); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e273d4a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,49 @@ +{ + "name": "test_1", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, + "epoll": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/epoll/-/epoll-4.0.0.tgz", + "integrity": "sha512-dENZbykco5w/vsFHuhD/5zla9VHm3htP1ROoX9MCc6L/7LVqGPFfcGS/g+/+pQLUclKw4uR9HnaZmsZ6fi5n+Q==", + "requires": { + "bindings": "^1.5.0", + "nan": "^2.14.1" + } + }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, + "lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" + }, + "nan": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", + "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==" + }, + "onoff": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onoff/-/onoff-6.0.0.tgz", + "integrity": "sha512-MLWs/s5vU0rfG+oTVXvGz7DIfAeynVEsZAZfbk8AL7gVVSaJerB2UxjkKRdUJIAMVFfdhgsZXZw+5eJAzdWspw==", + "requires": { + "epoll": "^4.0.0", + "lodash.debounce": "^4.0.8" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb3acae --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "test_1", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "onoff": "^6.0.0" + } +}