First Program: LED

From Neuromeka Wiki
Jump to: navigation, search
BB-Air


LED control

Now that you have your BB-Air board powered up, you'll naturally want to start programming it.

We'll begin by doing it manually through the Linux command line, and then compare that to doing it programmatically using:

  • node JS


1. Blinking the LED Manually

  • OFF
echo 0 > /sys/class/leds/beaglebone:green:usr0/brightness
echo 0 > /sys/class/leds/beaglebone:green:usr1/brightness
echo 0 > /sys/class/leds/beaglebone:green:usr2/brightness
echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness
  • ON
echo 1 > /sys/class/leds/beaglebone:green:usr0/brightness
echo 1 > /sys/class/leds/beaglebone:green:usr1/brightness
echo 1 > /sys/class/leds/beaglebone:green:usr2/brightness
echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness

2. Using the nodeJS

var exec = require("child_process").exec;

setTimeout(function() {
  LED_Off();
    setTimeout(function() {
      LED_On();
    }, 2000);
}, 2000);

function LED_Off() {
  exec('echo 0 > /sys/class/leds/beaglebone:green:usr0/brightness');
}

function LED_On() {
  exec('echo 1 > /sys/class/leds/beaglebone:green:usr0/brightness');
}