我是编程新手,所以请放轻松。我现在正在使用覆盆子pi和我想要做的事情,我希望覆盆子等待raw_input并从我的RFID输入。我试图在我的ser.read和user_input之间进行循环,但它对我来说并没有那么好。
import RPi.GPIO as GPIO
import time
import serial
GPIO.setwarnings(False)
user1 = '0000550835'
user2 = '2345'
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
ser = serial.Serial('/dev/ttyUSB0', 2400, timeout=0.5)
while True:
string = ser.read(12)
# Here is where i have tried to put in loop
user_input = raw_input('password:')
string = string[1:11]
if (string == user1):
print 'Welcome User1'
GPIO.output(7,True)
time.sleep(5)
GPIO.output(7,False)
if (user_input == user2):
print 'Welcome User2'
GPIO.output(7,True)
time.sleep(5)
GPIO.output(7,False)
else:
print 'Deny '