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 glowUser0() { b.digitalWrite("USR3", b.LOW); b.digitalWrite("USR0", b.HIGH); tempTimer = setTimeout(glowUser1,glowTime); } function glowUser1() { b.digitalWrite("USR0", b.LOW); b.digitalWrite("USR1", b.HIGH...