O'Reilly logo

Programming the BeagleBone by Yogesh Chavan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program to control LED by push button

Write the following code in it and save it as pushButton2.js. Run the program, keep button pressing and releasing. You should see the LED glowing when the button is pressed. When the button is released, the LED should be turned off.

var b = require('bonescript'); var inputPin = 'P8_16'; var outputPin = 'P8_10'; b.pinMode(inputPin, b.INPUT); b.pinMode(outputPin, b.OUTPUT); b.attachInterrupt(inputPin, true, b.CHANGE, interruptCallback); var exitTimer = setTimeout(exitProgram, 60000); function interruptCallback(pinObj) { if(pinObj.value==b.HIGH) { b.digitalWrite(outputPin, b.HIGH); } else { b.digitalWrite(outputPin, b.LOW); } } function exitProgram() { b.digitalWrite(outputPin, b.LOW); b.detachInterrupt(inputPin); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required