SHARE
TWEET

Untitled

a guest Nov 12th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import threading
  3. from playsound import playsound
  4.  
  5. class Vector3:
  6.   def __init__(self, x, y, z):
  7.     self.x = x
  8.     self.y = y
  9.     self.z = z
  10.  
  11. class Clock():
  12.     def __init__(self, v1 = 0, v2 = 0, v3 = 0):
  13.         self.hour = v1
  14.         self.minute = v2
  15.         self.second = v3
  16.  
  17.         self.startLoop()
  18.        
  19.     def reset(self):
  20.         self.second = 0
  21.         self.minute = 0
  22.         self.hour = 0  
  23.  
  24.     def set(self, v1, v2, v3):
  25.         self.hour = v1
  26.         self.minute = v2
  27.         self.second = v3
  28.        
  29.     def setHour(self, v1):
  30.         self.hour = v1
  31.        
  32.     def setMinute(self, v1):
  33.         self.minute = v1
  34.        
  35.     def setSecond(self, v1):
  36.         self.second = v1           
  37.        
  38.        
  39.     def startLoop(self):
  40.         t1 = threading.Thread(target=self.lLogic);
  41.         t1.start()     
  42.            
  43.     def lLogic(self):
  44.         while True:
  45.             time.sleep(1)
  46.            
  47.             self.second += 1
  48.            
  49.             if self.second > 59:
  50.                 self.second = 0
  51.                 self.minute += 1
  52.                
  53.                 if self.minute > 59:
  54.                     self.minute = 0
  55.                     self.hour += 1
  56.                    
  57.                     if self.hour > 11:
  58.                         self.hour = 0
  59.        
  60.                        
  61. class Alarm(Clock):
  62.     def __init__(self, v1 = 0, v2 = 0, v3 = 0):
  63.         self.hour = v1
  64.         self.minute = v2
  65.         self.second = v3
  66.  
  67.         self.listAlarms = []
  68.        
  69.         self.startLoop()
  70.    
  71.    
  72.     def addAlarm(self, v1, v2, v3):
  73.         self.listAlarms.append(Vector3(v1, v2, v3))
  74.    
  75.     def removeAlarm(self, v1 , v2, v3):
  76.         for i in range (len(self.listAlarms)):
  77.             if v1 == self.listAlarms[i].x and v2 == self.listAlarms[i].y and v3 == self.listAlarms[i].z:
  78.                 self.listAlarms.pop(i)
  79.  
  80.  
  81.     def startLoop(self):
  82.         t1 = threading.Thread(target=self.lLogic);
  83.         t2 = threading.Thread(target=self.lCheck);
  84.        
  85.         t1.start()
  86.         t2.start()
  87.        
  88.     def lCheck(self):
  89.         while True:
  90.             for i in range (len(self.listAlarms)):
  91.                 if self.hour == self.listAlarms[i].x and self.minute == self.listAlarms[i].y and self.second == self.listAlarms[i].z:
  92.                     print("Alarm")
  93.                     playsound('alarmsound.mp3')
  94.             time.sleep(1)
  95.                                    
  96.                                    
  97. OmasWecker = Alarm(12, 32, 56)
  98. OmasWecker.addAlarm(12, 33, 0)
  99.  
  100. while True:
  101.     print(OmasWecker.hour, " ", OmasWecker.minute, " ", OmasWecker.second)
  102.     time.sleep(1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top