Skip to content

Instantly share code, notes, and snippets.

@rxseger
Created December 18, 2016 20:59
Show Gist options
  • Save rxseger/2cb093b471c09f7019bbd02456038b0a to your computer and use it in GitHub Desktop.
Save rxseger/2cb093b471c09f7019bbd02456038b0a to your computer and use it in GitHub Desktop.
drive a 4-bit shift register via GPIO (2 outputs) on Raspberry Pi
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
CLOCK = 36 # G16
DATA = 7 # G4
GPIO.setwarnings(False)
GPIO.setup([CLOCK, DATA], GPIO.OUT, initial=GPIO.LOW)
def clock_in_data(bits):
#print "clock_in_data",bits
for i in range(0, len(bits)):
GPIO.output(DATA, bits[i])
# falling transition -> clocks in data
GPIO.output(CLOCK, True)
time.sleep(0.001)
GPIO.output(CLOCK, False)
# an interesting "bouncing" pattern
bits = [
[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1],
[0,0,1,0],
[0,1,0,0],
]
while True:
for line in bits:
clock_in_data(line)
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment