Skip to content

Instantly share code, notes, and snippets.

@cobrce
Created November 9, 2018 15:34
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 cobrce/6b7af4fd40d1e5604f885f4f9e910a5c to your computer and use it in GitHub Desktop.
Save cobrce/6b7af4fd40d1e5604f885f4f9e910a5c to your computer and use it in GitHub Desktop.
A script for raspberry pi to send value(s) to shift register(s) (74HC595) (python3.6)
import RPi.GPIO as io
import time
SH = 17
DS = 27
ST = 22
def send(value):
io.output(DS,0)
io.output(SH,0)
for i in range(8):
io.output(DS,((value >> i) & 1))
io.output(SH,1)
time.sleep(0.1)
io.output(SH,0)
time.sleep(0.1)
io.output(ST,1)
time.sleep(0.1)
io.output(ST,0)
time.sleep(0.1)
io.setwarnings(False)
io.setmode(io.BCM)
io.setup(DS,io.OUT)
io.setup(SH,io.OUT)
io.setup(ST,io.OUT)
while True:
print(f"SH = {SH}, DS = {DS}, ST = {ST}")
print("enter bytes(s) (in decimal) to send:")
try:
send(int(input()))
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment