Created
January 6, 2015 20:35
-
-
Save rbeiter/039371165e7b5b2a8194 to your computer and use it in GitHub Desktop.
RPi cycle for Holiday Light Fight
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
# adapted to RPi from http://bildr.org/2011/02/74hc595/# | |
# http://www.raspberrypi.org/forums/viewtopic.php?f=32&t=15874 | |
import RPi.GPIO as GPIO | |
import time | |
from array import * | |
# using an MCM Raspberry Pi GPIO Breakout Board with Paddle Terminals | |
SER_Pin=22 | |
RCLK_Pin=23 | |
SRCLK_Pin=24 | |
NUMBER_OF_SHIFT_REGISTERS=1 | |
NUMBER_OF_REGISTER_PINS=NUMBER_OF_SHIFT_REGISTERS * 8 | |
registerPins = [GPIO.HIGH] * NUMBER_OF_REGISTER_PINS | |
def setup(): | |
GPIO.setwarnings(False) # look into better way to avoid GPIO.setup warnings | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(SER_Pin, GPIO.OUT) | |
GPIO.setup(RCLK_Pin, GPIO.OUT) | |
GPIO.setup(SRCLK_Pin, GPIO.OUT) | |
clearRegisters() | |
def clearRegisters(): | |
for pin in range(NUMBER_OF_REGISTER_PINS): | |
registerPins[pin] = GPIO.HIGH | |
def writeRegisters(): | |
GPIO.output(RCLK_Pin, GPIO.LOW) | |
for pin in xrange(NUMBER_OF_REGISTER_PINS-1, -1, -1): | |
GPIO.output(SRCLK_Pin, GPIO.LOW) | |
GPIO.output(SER_Pin, registerPins[pin]) | |
GPIO.output(SRCLK_Pin, GPIO.HIGH) | |
GPIO.output(RCLK_Pin, GPIO.HIGH) | |
def setRegisterPin(index, value): | |
registerPins[index] = value | |
# ############# | |
setup() | |
while True: | |
for targetPin in xrange(NUMBER_OF_REGISTER_PINS): # light up each port in turn | |
for pin in xrange(NUMBER_OF_REGISTER_PINS): # we'll only set LOW (turn on) one port at a time | |
value = GPIO.LOW if pin==targetPin else GPIO.HIGH | |
setRegisterPin(pin, value) | |
writeRegisters() | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment