Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Spot-Welder-Control/Shift.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
84 lines (70 sloc)
2.19 KB
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 GPIO | |
import time | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
outpins = [22, 23, 24] | |
relayNumber = 2 | |
for i in outpins: | |
GPIO.setup(i, GPIO.OUT) | |
GPIO.output(i, GPIO.HIGH) | |
def Shift(output, relayNumber): | |
for i in range(8*relayNumber): | |
if output[i] == "1": | |
GPIO.output(23, GPIO.LOW) | |
elif output[i] == "0": | |
GPIO.output(23, GPIO.HIGH) | |
else: | |
print("ERROR") | |
GPIO.output(22, GPIO.HIGH) | |
GPIO.output(22, GPIO.LOW) | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.output(24, GPIO.LOW) | |
def demo(relayNumber): | |
connected = 12 | |
timer = 0.1 | |
while True: | |
for i in range(connected): | |
output = (i-1)*"0" + "1" + (8*relayNumber-i)*"0" | |
print(output) | |
Shift(output[::-1], relayNumber) | |
time.sleep(timer) | |
#timer = timer - timer/10 | |
def checkOutput(output, relayNumber): | |
if len(output)>8*relayNumber: | |
print("Only " + str(8*relayNumber) + " bits will be displayed") | |
elif len(output)<8*relayNumber: | |
output = output + "0"*(8*relayNumber-len(output)) | |
return output[::-1] | |
def binary(relayNumber): | |
output = input("What binary do you want to display? > ") | |
output = checkOutput(output, relayNumber) | |
Shift(output, relayNumber) | |
binary(relayNumber) | |
def relayIndex(relayNumber, currentBinary): | |
print(currentBinary) | |
output = input("What relay number do you want to toggle? > ") | |
if int(output) > len(currentBinary)-1: | |
print("This relay number doesn't exist") | |
elif 0 <= int(output) < len(currentBinary): | |
output = int(output) | |
if currentBinary[output] == "1": | |
currentBinary = currentBinary[:output] + "0" + currentBinary[output+1:] | |
elif currentBinary[output] == "0": | |
currentBinary = currentBinary[:output] + "1" + currentBinary[output+1:] | |
else: | |
print("Invalid Input") | |
Shift(currentBinary[::-1], relayNumber) | |
relayIndex(relayNumber, currentBinary) | |
def main(relayNumber): | |
output = "00000000"*relayNumber | |
Shift(output, relayNumber) | |
output = input("What input do you want? Binary/Demo/Index > ") | |
if output == "Binary": | |
binary(relayNumber) | |
elif output == "Demo": | |
demo(relayNumber) | |
elif output == "Index": | |
relayIndex(relayNumber, "00000000"*relayNumber) | |
else: | |
main(relayNumber) | |
main(relayNumber) |