Tag Archives: LEDs

Project: BBB Admin Page – Running a Basic Node.js Program

The default Debian distro for BBB includes the Cloud9 Integrated Development Environment (IDE), which we can use to run a very basic program to blink LEDs. The Cloud9 IDE is available over the virtual USB to Ethernet port’s default IP address and port 3000:

Cloud9 IDE

Cloud9 Integrated Development Environment (IDE)

We’ll be using node.js technology to handle our requests, so let’s first confirm that we have node installed on our system. The best way to do this to simple ask for the version installed, if we get a response and the response is a latest build, then we’re ready to move on. We can issue a command directly from the Cloud9 bash window:

Get node.js version

Test node.js installation

We’ll be writing our programs in JavaScript within the node.js infrastructure. To get started we’ll load the demo/blinkled.js.

blinkled.js program

blinkled.js program

  • Line 1: Initialize the bonescript library
  • Line 3: Defines the leds variable, by referencing user space names for known outputs
  • Lines 5-7: Defines the leds as outputs
  • Lines 9-12: Sets the leds to off state
  • Line 14: Defines a timer that will go call the toggle function every¬†1000ms (1sec)
  • Line 16-22: If the led state is off, turn if on, else turn it off

We can now run the program by typing the following into the bash window: node demo/blinkled.js. The end result is the following:

Now that we have the programming environment in place, we’ll step up to create a web page that can allow us to control the LEDs.