Advertisement
noam76

class with function

Apr 22nd, 2019
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import time
  2. # import RPi.GPIO as GPIO
  3. operation_motor_start = 0
  4. motor_running = False
  5. MOTOR_TIMEOUT = 3
  6. target_temp = 23
  7. local_temp = 20
  8.  
  9. class damper_motor:
  10.   def __init__(self, pinA, pinB, MOTOR_TIMEOUT):
  11.     self.pinA = pinA
  12.     self.pinB = pinB
  13.     self.MOTOR_TIMEOUT = MOTOR_TIMEOUT
  14.  
  15.   def damper_motor_driver(self):
  16.     global operation_motor_start
  17.     global motor_running
  18.     if motor_running == True:
  19.       current_motor_time = time.time()
  20.       if current_motor_time - operation_motor_start > MOTOR_TIMEOUT:
  21.         motor_running = False
  22.         operation_motor_start = 0
  23.         #GPIO.output(_MotorR,GPIO.LOW)
  24.         #GPIO.output(_MotorL,GPIO.LOW)
  25.         print("GOOD The time is ending")
  26.  
  27.   def open_damper(self):
  28.     global operation_motor_start
  29.     global motor_running
  30.     motor_running = True
  31.     operation_motor_start = time.time()
  32.     #GPIO.output(_MotorR,GPIO.LOW)
  33.     #GPIO.output(_MotorL,GPIO.HIGH)
  34.  
  35.   def close_damper(self):
  36.     global operation_motor_start
  37.     global motor_running
  38.     motor_running = True
  39.     print(motor_running)
  40.     operation_motor_start = time.time()
  41.     #GPIO.output(_MotorR,GPIO.HIGH)
  42.     #GPIO.output(_MotorL,GPIO.LOW)
  43.  
  44. damper_room1 = damper_motor(2,3,MOTOR_TIMEOUT)
  45. damper_room2 = damper_motor(4,5,MOTOR_TIMEOUT)
  46. damper_room3 = damper_motor(6,7,MOTOR_TIMEOUT)
  47. damper_room4 = damper_motor(8,9,MOTOR_TIMEOUT)
  48.  
  49. while True:
  50.   damper_room1.damper_motor_driver()
  51.   if target_temp > local_temp:
  52.     damper_room1.close_damper()
  53.     print(motor_running)
  54.     local_temp = 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement