import time # import RPi.GPIO as GPIO operation_motor_start = 0 motor_running = False MOTOR_TIMEOUT = 3 target_temp = 23 local_temp = 20 class damper_motor: def __init__(self, pinA, pinB, MOTOR_TIMEOUT): self.pinA = pinA self.pinB = pinB self.MOTOR_TIMEOUT = MOTOR_TIMEOUT def damper_motor_driver(self): global operation_motor_start global motor_running if motor_running == True: current_motor_time = time.time() if current_motor_time - operation_motor_start > MOTOR_TIMEOUT: motor_running = False operation_motor_start = 0 #GPIO.output(_MotorR,GPIO.LOW) #GPIO.output(_MotorL,GPIO.LOW) print("GOOD The time is ending") def open_damper(self): global operation_motor_start global motor_running motor_running = True operation_motor_start = time.time() #GPIO.output(_MotorR,GPIO.LOW) #GPIO.output(_MotorL,GPIO.HIGH) def close_damper(self): global operation_motor_start global motor_running motor_running = True print(motor_running) operation_motor_start = time.time() #GPIO.output(_MotorR,GPIO.HIGH) #GPIO.output(_MotorL,GPIO.LOW) damper_room1 = damper_motor(2,3,MOTOR_TIMEOUT) damper_room2 = damper_motor(4,5,MOTOR_TIMEOUT) damper_room3 = damper_motor(6,7,MOTOR_TIMEOUT) damper_room4 = damper_motor(8,9,MOTOR_TIMEOUT) while True: damper_room1.damper_motor_driver() if target_temp > local_temp: damper_room1.close_damper() print(motor_running) local_temp = 25