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

Dancing LEDs

BeagleBone has four onboard LEDs adjacent to each other. Let's create an LED on/off pattern so that we get an illusion of dancing LEDs. We will follow the turning on the LED sequence: USER0 -> USER1 -> USER2 -> USER3 -> USER0 -> USER1 -> USER2 -> USER3 -> USER0, and so on. This will give the illusion that light is traveling from USER0 to USER3 in loops. Type the following program in Cloud9, save it as danceLEDs.js and run it. The code for danceLEDs.js is as follows:

var b = require('bonescript'); var glowTime = 100; var exitTime = 30000; var tempTimer; b.pinMode("USR0", b.OUTPUT); b.pinMode("USR1", b.OUTPUT); b.pinMode("USR2", b.OUTPUT); b.pinMode("USR3", b.OUTPUT); var exitTimer = setTimeout(exitProgram,exitTime); glowUser0(); function ...

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