Created
February 24, 2015 05:16
-
-
Save wblakecaldwell/410822633e8004cd7dec to your computer and use it in GitHub Desktop.
cylon.py - Pulse an LED bar like a Cylon - Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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