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)
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 ...