1 - The following code runs just fine in IDLE and Pycharm on my PC (except the GPIO parts, of course) but when run in python, the string manipulation parts don't function as intended. (See comments in code)
2 - I tried using GPIO.cleanup() under an eventually: in the try: loop. It says nothing to clean up. However, without it, the second time I run this it says channels are in use. I cheated and added a GPIO.setwarnings(False) in, but I'd like to know how to avoid that.
Any help would be GREATLY appreciated!
Code: Select all
import RPi.GPIO as GPIO import time from datetime import datetime in1 = 16 in2 = 18 GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(in1, GPIO.OUT) GPIO.setup(in2, GPIO.OUT) GPIO.output(in1, True) GPIO.output(in2, True) mem_num = "" valid_card = False mem_file = open("members.txt", "r") mem_list = mem_file.readlines() mem_file.close() while True: try: mem_num = input("?") if mem_num == "1": break valid_card = mem_num.startswith("VHA1") #The following line seems to be where my trouble is. mem_num = str(mem_num.replace("VHA100", "")) #Any valid card scanned start withs 'VHA100'. The following line #in Python returns the entire original string, including the 'VHA100' prefix. print(mem_num) if (mem_num + "\n") in mem_list and valid_card: print("Valid") GPIO.output(in1, False) GPIO.output(in2, False) time.sleep(.5) GPIO.output(in1, True) GPIO.output(in2, True) except Exception as err: now = datetime.now() dt_string = now.strftime("%d/%m/%Y %H:%M:%S") print (err, "***", dt_string)