Skip to content

Instantly share code, notes, and snippets.

@wblakecaldwell
Created February 24, 2015 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wblakecaldwell/410822633e8004cd7dec to your computer and use it in GitHub Desktop.
Save wblakecaldwell/410822633e8004cd7dec to your computer and use it in GitHub Desktop.
cylon.py - Pulse an LED bar like a Cylon - Raspberry Pi
#
# Pulse an LED bar like a Cylon
#
# This is my Raspberry Pi "Hello World".
#
import RPi.GPIO as GPIO
import time
# blinking function
def blink(pin):
GPIO.output(pin,GPIO.HIGH)
time.sleep(0.05)
GPIO.output(pin,GPIO.LOW)
try:
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO pins
pins = [35, 37, 7, 11, 13, 15, 19, 21, 23, 29]
for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin,GPIO.LOW)
# build reversed list
rev_pins = pins[::-1]
del rev_pins[-1]
del rev_pins[0]
# Cylon time!
while True:
for pin in pins:
blink(pin)
for pin in rev_pins:
blink(pin)
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment