17 lines
389 B
JavaScript
Raw Normal View History

2020-09-11 12:42:13 +01:00
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 );
} );