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 read from push button

Write the following code in Cloud9 and save it as pushButton.js. Run the program, keep the button pressing and releasing. You should see Button is pressed printed when you press the button and Button is released when the button is released. The program will exit after a minute automatically.

var b = require('bonescript');var loopTime = 1000; var exitTime = 60000; var button = 'P8_16'; b.pinMode(button, b.INPUT); var loopTimer = setInterval(check,loopTime); var exitTimer = setTimeout(exitProgram,exitTime); function check() { b.digitalRead(button, checkButton); } function checkButton(pinObj) { if(pinObj.value == b.HIGH) { console.log("Button is pressed"); } else { console.log("Button is released"); } } function exitProgram() ...

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