74HC595 Shift Register, Raspberry Pi

74HC595 Shift Register, Raspberry Pi
#!/usr/bin/env python import RPi.GPIO as GPIO import time import math latchPin = 6 clockPin = 19 dataPin = 13 def setup(): GPIO.setmode(GPIO.BCM) GPIO.setup(latchPin, GPIO.OUT) GPIO.setup(clockPin, GPIO.OUT) GPIO.setup(dataPin, GPIO.OUT) GPIO.output(latchPin, GPIO.LOW) GPIO.output(clockPin, GPIO.LOW) GPIO.output(dataPin, GPIO.LOW) def onoff(n, coin): GPIO.output(clockPin, GPIO.LOW) if ((math.fmod(n,2)==0)==coin): GPIO.output(dataPin, GPIO.HIGH) else: GPIO.output(dataPin, GPIO.LOW) GPIO.output(clockPin, GPIO.HIGH) GPIO.output(dataPin, GPIO.LOW) def loop(): coin = 0 while True: GPIO.output(latchPin, GPIO.LOW) GPIO.output(dataPin, GPIO.LOW) GPIO.output(clockPin, GPIO.LOW) for i in range(0, 16): onoff(i, coin) GPIO.output(clockPin, GPIO.LOW) GPIO.output(latchPin, GPIO.HIGH) if coin == 0: coin = 1 else: coin = 0 time.sleep(1) def destroy(): GPIO.cleanup() if __name__ == '__main__': setup() try: loop() except KeyboardInterrupt: destroy()