Here’s a short Python script to toggle an LED using GPIO.
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
pin = 15
blinkSpeed = 1/5.0 #blink x times per second
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)
try:
while True:
print('PIN {} is going HIGH'.format(pin))
GPIO.output(pin, GPIO.HIGH)
time.sleep(blinkSpeed / 2.0)
print('PIN {} is going LOW'.format(pin))
GPIO.output(pin, GPIO.LOW)
time.sleep(blinkSpeed / 2.0)
finally:
print 'finally'
![20150418_173116[1]](https://tagenigma.com/blog/wp-content/uploads/2015/04/20150418_1731161-169x300.jpg)