Issue
I am trying to control GPIO pins through dictionary pins: My code:
var gpio = require('onoff').Gpio;
var rpi_board = [{'pin_17_in':new gpio(17,'in')},
{'pin_27_in':new gpio(27,'in')},
{'pin_19_out':new gpio(19,'out')},
{'pin_26_out':new gpio(26,'out')}];
var outputChannels = [
{ physicalPin: rpi_board.pin_19_out, pin:19, location:"EntraceLight", meter: "EntraceLightON", active:true, device_id:2 },
{ physicalPin: rpi_board.pin_26_out, pin:26, location:"BackdoorLight", meter: "BackdoorLightON", active:true, device_id:3 }
];
console.log("Set outputChannels[0] to high: ")
console.log(outputChannels[0].physicalPin.writeSync(1))
Present output:
'Caught exception: TypeError: Cannot read property \'writeSync\' of undefined'
TypeError: Cannot read property 'writeSync' of undefined
Solution
You wanted to create one dictionary instead of 4 inside an array
var rpi_board = {
'pin_17_in':new gpio(17,'in'),
'pin_27_in':new gpio(27,'in'),
'pin_19_out':new gpio(19,'out'),
'pin_26_out':new gpio(26,'out')
};
Answered By - Konrad Answer Checked By - Clifford M. (WPSolving Volunteer)