Beaglebone and flashing led example

In this example we connect 5 LEDs to our Beaglebone board and then flash them ona nd off, the hello world of examples

You will be able to see that we used the following pins

var leds = [“P9_12”, “P9_14”, “P9_16”, “P9_22”, “P9_20”];

This corresponds to the following

Schematics

This schematic only shows only 1 resistor and LED

Code

I used the cloud9 IDE and this example is written in JavaScript, other language examples will follow

[codesyntax lang=”javascript”]

#!/usr/bin/env node
var b = require('bonescript');

var leds = ["P9_12", "P9_14", "P9_16", "P9_22", "P9_20"];

for(var i in leds) {
    b.pinMode(leds[i], b.OUTPUT);
}

var state = b.LOW;
for(var i in leds) {
    b.digitalWrite(leds[i], state);
}

setInterval(toggle, 1000);

function toggle() {
    if(state == b.LOW) state = b.HIGH;
    else state = b.LOW;
    for(var i in leds) {
        b.digitalWrite(leds[i], state);
    }
}

[/codesyntax]

Run this and you should see all 5 LEDs connected flashing on and off

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :