We need installed Adafruit_BBIO.GPIO library and Python.
We will use 05 LEDs for this purpose. Also, we use following general purpose pins of Beaglebone Black for this purpose.
First we import Adafruit_BBIO.GPIO library and python time library.
import Adafruit_BBIO.GPIO as GPIO
import time
Then we setup the following pins as outputs. You do not have to setup the P8_2. It is a ground pin we use.
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)
We take the LEDs into an array.
leds = [ “P8_10”, “P8_12”, “P8_14”, “P8_16”, “P8_18”]
Then we start a loop to play the LEDs continuously.
while (1):
Here, we define a variable to go through each LED.
a = 0
Use a IF condition to check the value of “a”
if (a<1):
We start a FOR loop to move ascending order through LEDs if “a” equals to zero.
for eachLED in leds:
GPIO.output(eachLED,GPIO.HIGH)
Below what we meant is, as we move from one LED to next, we turn off the previous LED.
if (a > 0):
GPIO.output(leds[a-1],GPIO.LOW)
You can apply a small delay for your play.
time.sleep(0.1)
We say to “a” variable to increase its value in each loop.
a = a + 1
After going to the last led, we descend back to first.
if(a > 4):
a = a -1
for eachLED in leds: # count from 7 to 0
GPIO.output(leds[a],GPIO.HIGH)
If you have understood the ascending procedure, I hope the thing we have done below is clear to you.
if (a < 4):
GPIO.output(leds[a+1],GPIO.LOW)
time.sleep(0.1)
a = a – 1
OK, That’s all. Download the python code here.