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

Quick program to blink onboard LED

Now that we have written a program to turn the USER3 LED on and off, let's write a program to blink this LED. Type the following program in Cloud9, save it as blinkOnboardLED.js, and run it. Your USER3 LED should start blinking each second. This is an infinite loop. You can stop the loop by clicking on the red Stop button in Cloud9. The code for blinkOnboardLED.js is as follows:

var b = require('bonescript');
var state = b.HIGH;

b.pinMode("USR3", b.OUTPUT);
b.digitalWrite("USR3", state);

setInterval(blink,1000);

function blink()
{
  if(state == b.LOW)
    state = b.HIGH;
  else
    state = b.LOW;
  b.digitalWrite("USR3", state);
}

Program explanation

We want to blink the LED after each second. If one wants to code this in C, ...

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