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 LEDs

Let's write LED blinking code in Python. Connect one external LED in series with a resistor to pin P8_10 like we did in Chapter 3, Blinking External LEDs. Type the following program in Cloud9, save it as blink_external_LED.py and run. You should be able to see an LED blinking each second:

The code for blink_external_LED.py is as follows:

#!/usr/bin/python
from time import sleep       ##Needed to call sleep()
import Adafruit_BBIO.GPIO as GPIO

led = "P8_10"

GPIO.setup(led,GPIO.OUT)

while True:
    GPIO.output(led,GPIO.HIGH)
    sleep(1)
    GPIO.output(led,GPIO.LOW)
    sleep(1)

Explanation

Now, let's go through the above-mentioned code snippet one step at a time. If you observed, there is no semicolon (;) at the end of lines in Python. There ...

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