Raspberry PI 2 – Alternating LEDs

The following Python alternates between two LEDs and then goes dark before repeating.

20150418_211943[1]

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time
led_pin = 15
led_pin2 = 37
blinkSpeed = 5/2.0 #blink x times per second

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(led_pin, GPIO.OUT)
GPIO.setup(led_pin2, GPIO.OUT)

try:
 while True:

  GPIO.output(led_pin, GPIO.HIGH)
  GPIO.output(led_pin2, GPIO.LOW)
  time.sleep(blinkSpeed / 3.0)

  GPIO.output(led_pin, GPIO.LOW)
  GPIO.output(led_pin2, GPIO.HIGH)
  time.sleep(blinkSpeed / 3.0)

  GPIO.output(led_pin, GPIO.LOW)
  GPIO.output(led_pin2, GPIO.LOW)
  time.sleep(blinkSpeed / 3.0)

finally:
 print 'finally'