Using a Button
As you’ve noticed, the functions in bonescript are similar to Arduino’s. If we are to use an input device such as a button, switch, etc, we only need to change the direction using pinMode:
var b = require('bonescript');
b.pinMode("P9_12", b.INPUT);
The script below reads the state of a button attached to P9_11. If that button is pressed, the LED at P9_12 will turn on. Otherwise, the LED remains off.
var b = require('bonescript');
b.pinMode("P9_12", b.OUTPUT);
b.pinMode("P9_11", b.INPUT);
setInterval(readButton, 500);
function readButton() {
b.digitalRead("P9_11", toggle);
}
function toggle(x){
console.log(x.value);
b.digitalWrite("P9_12", x.value);
}



