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 blink external LED

Now that everything is connected, type the following program in Cloud9, save it as blinkExternalLED.js and run. You should be able to see the LED blinking each second:

var b = require('bonescript');
var led = "P8_10";
var state = b.HIGH;
var loopTime = 1000;
var exitTime = 30000;

b.pinMode(led, b.OUTPUT);
b.digitalWrite(led, state);

var loopTimer = setInterval(blink, loopTime);
var exitTimer = setTimeout(exitProgram,exitTime);

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

function exitProgram()
{
   b.digitalWrite(led,b.LOW);
   clearInterval(loopTimer);
}

Explanation

This is the exact same program that we did in the previous chapter except we put LED as string P8_10 ...

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