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 dance external LEDs in both directions

Write the following program in Cloud9 and save it as danceExternalLEDs.js. Run it and you should see dancing LEDs in both directions:

var b = require('bonescript'); var loopTime = 50; var exitTime = 20000; var reverse_direction; var index; var LEDs = ["P8_7","P8_9","P8_11","P8_13","P8_15","P8_17","P8_19"]; for(index in LEDs) { b.pinMode(LEDs[index],b.OUTPUT); } index=0; var loopTimer = setInterval(danceLEDs, loopTime); var exitTimer = setTimeout(exitProgram,exitTime); function danceLEDs() { switch(index) { case 0: b.digitalWrite(LEDs[index+1],b.LOW); b.digitalWrite(LEDs[index++],b.HIGH); reverse_direction = false; break; case (LEDs.length-1): b.digitalWrite(LEDs[index-1],b.LOW); b.digitalWrite(LEDs[index--],b.HIGH); ...

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