Sep-23-2024, 11:00 PM
(This post was last modified: Sep-24-2024, 03:15 AM by deanhystad.)
my messy and badly written code is to activate a 6 channel relay to open solenoids via the raspberry pi on my display cabinet.
it works, sort of. Iff the correct code is entered it opens and returns back to input question but when the correct code is entered again the program ends. I was wondering if maybe the input needed to be cleared before it asks again.
Hope your eyes don't bleed reading it but it was my first attempt at python code
it works, sort of. Iff the correct code is entered it opens and returns back to input question but when the correct code is entered again the program ends. I was wondering if maybe the input needed to be cleared before it asks again.
Hope your eyes don't bleed reading it but it was my first attempt at python code
import RPi.GPIO as GPIO # Import GPIO Module
import time # just in case
import os # just in case
from time import sleep # Import sleep Module for timing
GPIO.setmode(GPIO.BCM) # Configures how we are describing our pin numbering
GPIO.setwarnings(False) # Disable Warnings
OutputPins = [2, 3, 4, 17, 22, 27] # Set the GPIO pins that are required
def start(): # create input and correct entry code
print("")
lock = input("Enter The Unlock Code: ")
unlock = ["007"] # Set unlock code
while lock not in unlock: # Check for correct input
lock = input("Enter The Unlock Code: ")
start()
# Activate pins and relay
for i in OutputPins:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, False)
# Switch relay off
time.sleep(10)
for i in OutputPins:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, True)
start() # return to input question
deanhystad write Sep-24-2024, 03:15 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
