Various Beaglebone and flashing LED examples

In this example we connect 6 LEDs to our Beaglebone board and then flash them on and off, we have a Bonescript and Python code examples

In our example we use P8 8 to 18 for each LED and P8_2 for a common ground- you can see this here in this pinout

Parts List

BeagleBone Black TI AM3358 Cortex-A8 development BB-Black Rev.C

Code

Bonescript example

[codesyntax lang=”javascript”]

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

var leds = ["P8_8", "P8_10", "P8_12", "P8_14", "P8_16", "P8_18"];

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]

Python example 1

[codesyntax lang=”python”]

import Adafruit_BBIO.GPIO as GPIO
import time
 
GPIO.setup("P8_8", GPIO.OUT)
GPIO.setup("P8_10", GPIO.OUT)
GPIO.setup("P8_12", GPIO.OUT)
GPIO.setup("P8_14", GPIO.OUT)
GPIO.setup("P8_16", GPIO.OUT)
GPIO.setup("P8_18", GPIO.OUT)
 
while True:
    GPIO.output("P8_8", GPIO.HIGH)
    GPIO.output("P8_10", GPIO.LOW)
    GPIO.output("P8_12", GPIO.HIGH)
    GPIO.output("P8_14", GPIO.LOW)
    GPIO.output("P8_16", GPIO.HIGH)
    GPIO.output("P8_18", GPIO.LOW)
    time.sleep(0.5)
    GPIO.output("P8_8", GPIO.LOW)
    GPIO.output("P8_10", GPIO.HIGH)
    GPIO.output("P8_12", GPIO.LOW)
    GPIO.output("P8_14", GPIO.HIGH)
    GPIO.output("P8_16", GPIO.LOW)
    GPIO.output("P8_18", GPIO.HIGH)
    time.sleep(0.5)

[/codesyntax]

Python example 2

[codesyntax lang=”python”]

import Adafruit_BBIO.GPIO as GPIO
import time
 
GPIO.setup("P8_8", GPIO.OUT)
GPIO.setup("P8_10", GPIO.OUT)
GPIO.setup("P8_12", GPIO.OUT)
GPIO.setup("P8_14", GPIO.OUT)
GPIO.setup("P8_16", GPIO.OUT)
GPIO.setup("P8_18", GPIO.OUT)
 
while True:
    GPIO.output("P8_8", GPIO.HIGH)
    GPIO.output("P8_10", GPIO.HIGH)
    GPIO.output("P8_12", GPIO.HIGH)
    GPIO.output("P8_14", GPIO.HIGH)
    GPIO.output("P8_16", GPIO.HIGH)
    GPIO.output("P8_18", GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output("P8_8", GPIO.LOW)
    GPIO.output("P8_10", GPIO.LOW)
    GPIO.output("P8_12", GPIO.LOW)
    GPIO.output("P8_14", GPIO.LOW)
    GPIO.output("P8_16", GPIO.LOW)
    GPIO.output("P8_18", GPIO.LOW)
    time.sleep(0.5)

[/codesyntax]

LEAVE A REPLY

Please enter your comment!
Please enter your name here