Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. import machine
  2. import utime
  3.  
  4. class GrowBed:
  5.  
  6.     def __init__(self, GB_IO):
  7.         self.fill_time = 15
  8.         self.drain_time = 15
  9.         self.remaining_fill_time = 10
  10.         self.remaining_drain_time = 10
  11.         self.is_draining = True
  12.         self.start_drain_time = 0
  13.         self.start_fill_time = 0
  14.         self.GB_IO = GB_IO
  15.  
  16. def start_filling(self):
  17.     self.is_draining = False
  18.     self.remaining_drain_time = self.drain_time
  19.     self.GB_IO.high()
  20.    
  21.  
  22.  
  23.  
  24. def start_draining(self):
  25.     self.is_draining = True
  26.     self.remaining_fill_time = self.fill_time
  27.     self.GB_IO.low()
  28.  
  29.  
  30.        
  31.    
  32. #Set Grow Bed Pin's then make classes for each bed, then created a list of the newly made class-object
  33. back = GrowBed(machine.Pin(5, machine.Pin.OUT))
  34. left = GrowBed(machine.Pin(4, machine.Pin.OUT))
  35. right = GrowBed(machine.Pin(0, machine.Pin.OUT))
  36. Growbeds = [back, left, right]
  37.  
  38. one_second_in_ms = 1000
  39. previoustime = 0
  40. currenttime = utime.ticks_ms()
  41.  
  42. while True:
  43.     currenttime = utime.ticks_ms()
  44.     if currenttime - previoustime >= one_second_in_ms:
  45.         print('heartbeat')
  46.         for self in Growbeds:
  47.             if self.is_draining:
  48.                 self.remaining_drain_time -= 1
  49.                 if self.remaining_drain_time <= 0:
  50.                     start_filling(self)
  51.                     print('now filling')
  52.             else:
  53.                 self.remaining_fill_time -= 1
  54.                 if self.remaining_fill_time <=0:
  55.                     start_draining(self)
  56.                     print('now draining')
  57.         previoustime = currenttime
  58.         utime.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement