0
안녕하세요 사람들은 GPIO.input (22)가 메소드를 호출하기 전에 gpio.input (11)을 기다릴 때마다 내가 원하는 모든 실수를 발견 할 수있었습니다. 시간 그러나 그것은 루프를 떠날 수없는 것 같습니다. 감사합니다Python raspberry pi GPIO 논리 오류
from datetime import datetime
import time
import threading
import MySQLdb
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(22, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
db = MySQLdb.connect("localhost","root","root","test")
cursor = db.cursor()
class Variable:
count = 0
people = 0
times = 0
decision = 0
choice = 0
def countdown():
GPIO.output(15, False)
time.sleep(5)
GPIO.output(15, True)
t = threading.Timer(5.0, countdown)
def enterexit():
global t # You need this to tell Python that you're going to change the global t variable. If you don't do this, using 't = ..' will just create a local t variable.
if int(Variable.choice == 1):
print("Entered")
print ("TIME: " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sql = """INSERT INTO `timing`(`Time`, `Date`) VALUES (CURTIME(), CURDATE())"""
t.start()
else:
if(Variable.decision == 1):
print("Entered")
print ("TIME: " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sql = """INSERT INTO `timing`(`Time`, `Date`) VALUES (CURTIME(), CURDATE())"""
t.cancel()
t.join() # here you block the main thread until the timer is completely stopped
t = threading.Timer(5.0, countdown)
t.start()
elif(Variable.decision == 2):
print("Exit")
print ("TIME: " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sql = """INSERT INTO `timing`(`Time`, `Date`) VALUES (CURTIME(), CURDATE())"""
t.cancel()
t.join() # here you block the main thread until the timer is completely stopped
t = threading.Timer(5.0, countdown)
t.start()
while True:
global sensor1
global sensor2
global Time1
global Time2
if GPIO.input(22):
Time1 = datetime.now().strftime('%H%M%S')
while True:
if GPIO.input(11):
GPIO.output(18, False)
GPIO.output(18, True)
Time2 = datetime.now().strftime('%H%M%S')
if(Time1 < Time2):
Variable.count+=1
Variable.choice += 1
Variable.people += 1
Variable.decision = 1
enterexit()
break
else:
print("Waiting")
elif GPIO.input(11):
Time2 = datetime.now().strftime('%H%M%S')
while True:
if GPIO.input(22):
GPIO.output(7, False)
GPIO.output(7, True)
Variable.count-=1
Time1 = datetime.now().strftime('%H%M%S')
if(Time2 < Time1):
Variable.people -= 1
print(Variable.people)
Variable.decision = 2
enterexit()
break
else:
print("Waiting")
else:
Variable.count = 0
db.close()