Created
November 9, 2018 15:34
-
-
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)
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
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