Skip to content

Instantly share code, notes, and snippets.

@shepting
Created March 13, 2014 22:24
Show Gist options
  • Save shepting/9538356 to your computer and use it in GitHub Desktop.
Save shepting/9538356 to your computer and use it in GitHub Desktop.
BeagleBone Black sample button/transistor switch code
var b = require('bonescript');
var switchIn = "P9_21";
var transistorOut = "P9_41";
b.pinMode(transistorOut, b.OUTPUT);
b.pinMode(switchIn, b.INPUT);
setInterval(toggle, 100);
console.log("started");
function toggle() {
b.digitalRead(switchIn, readFunction);
function readFunction(x) {
console.log("Switch value: " + x.value);
if (x.value == 0) {
console.log("pressed");
b.digitalWrite(transistorOut, b.HIGH);
} else {
b.digitalWrite(transistorOut, b.LOW);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment