Home / Tutorials / BeagleBone Tutorial / Blink a LED with Bonescript
beaglebone black adc

Blink a LED with Bonescript

Blinking On-board LEDs

The simplest bonescript we can create right now is to blink one of the four user LEDs. The user LEDs are those four blue LEDs just above the miniUSB port:


On Cloud9 IDE (, open a new file (click the + tab) and then paste the following script:

Click on the “run” button and you should see the right most LED blink every second.

This might confuse some Arduino users here (you said the transition is easy!). There is no setup() and loop() functions on bonescript. As always, the code starts at the very first line.

The line:

is very important as it loads the bonescript library. The rest of the lines are then executed. Variables on javascript d on't require specific data type declaration like int, char, etc. The data type is automatically determined once you assign some object to the variable. Here, the require() Node.JS function returns the bonescript module.

Once we loaded the bonescript module, we are ready to use its functions, constants, etc. We then created a variable named state with a value b.LOW. LOW is one of those bonescript constants.

If you want part of the code to loop continuously, you need to create some function (toggle() in this example) and wrap it around the javascript setInterval() function. Here, the setInterval() function loops every second.

The toggle() function checks the state of the state variable and complements (inverses) it. That state variable is then use to define the status of USR0 via the digitalWrite() function.

Blinking an External LED

We can also use an external LED and change the name of the pin on the program above. For example, if we will attach an LED to GPIO_60 or pin P9_12 (as shown on the diagram), the script becomes:

Beaglebone Black External LED

Save the file and click the “run” button again. The LED on P9_12 should now be blinking.

Check Also

beaglebone black adc

Controlling a Servo Motor with BoneScript

Using the Beaglebone Black's PWM Bonescript also includes an analogWrite function which utilizes the 8 …