Hi,
I have worked with various different development platforms before, though mostly in C/C++, so a lot of the Bonescript/Node.js stuff is very new to me, and I am having some trouble with some very simple tasks…
Recently I was trying to take in push button switches and in an effort to build a better understanding, after looking at the demos, I decided to play around on my own. the following code works fine:
`
var b = require(‘bonescript’);
var inputPin = “P8_19”;
var ledPin = [“USR3”, “USR2”, “USR1”, “USR0”];
var mydelay = 100;
console.log(‘Please press the button to flash the LEDs’);
b.pinMode(inputPin, b.INPUT);
b.pinMode(ledPin[0], b.OUTPUT);
b.pinMode(ledPin[1], b.OUTPUT);
b.pinMode(ledPin[2], b.OUTPUT);
b.pinMode(ledPin[3], b.OUTPUT);
setInterval(switchRead, 100);
function switchRead(x) {
b.digitalRead(inputPin, setLED);
}
function setLED(x) {
b.digitalWrite(ledPin[0], x.value);
b.digitalWrite(ledPin[1], x.value);
b.digitalWrite(ledPin[2], x.value);
b.digitalWrite(ledPin[3], x.value);
}
`
But the following code (change the inputPin to P8_4) will not work…
`
var b = require(‘bonescript’);
var inputPin = “P8_4”;
var ledPin = [“USR3”, “USR2”, “USR1”, “USR0”];
var mydelay = 100;
console.log(‘Please press the button to flash the LEDs’);
b.pinMode(inputPin, b.INPUT);
b.pinMode(ledPin[0], b.OUTPUT);
b.pinMode(ledPin[1], b.OUTPUT);
b.pinMode(ledPin[2], b.OUTPUT);
b.pinMode(ledPin[3], b.OUTPUT);
setInterval(switchRead, 100);
function switchRead(x) {
b.digitalRead(inputPin, setLED);
}
function setLED(x) {
b.digitalWrite(ledPin[0], x.value);
b.digitalWrite(ledPin[1], x.value);
b.digitalWrite(ledPin[2], x.value);
b.digitalWrite(ledPin[3], x.value);
}
`
and results in the following message:
`
/usr/local/lib/node_modules/bonescript/my.js:57
if(slot[0])
TypeError: Cannot read property ‘0’ of null
at Object.exports.load_dt (/usr/local/lib/node_modules/bonescript/my.js:57:20)
at Object.exports.create_dt (/usr/local/lib/node_modules/bonescript/my.js:123:33)
at Object.exports.setPinMode (/usr/local/lib/node_modules/bonescript/hw_capemgr.js:83:12)
at Object.f.pinMode (/usr/local/lib/node_modules/bonescript/index.js:160:15)
at Object. (/var/lib/cloud9/demo/input.js:8:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
[Process stopped]
`
Is there another way to address this GPIO pin? The pinout I have for the header shows this as GPIO_39, so I see no reason it shouldn’t work the same…