Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. from sense_hat import SenseHat
  2. import time
  3. import json
  4.  
  5. sense = SenseHat()
  6. json_file = []
  7.  
  8.  
  9. class TempRange(object):
  10. def __init__(self, cold_max, comfortable_min, comfortable_max, hot_min):
  11. self.cold_max = cold_max
  12. self.comfortable_min = comfortable_min
  13. self.comfortable_max = comfortable_max
  14. self.hot_min = hot_min
  15.  
  16. @classmethod
  17. def readJsonintoList(cls, json_file):
  18. with open("config.json") as json_file:
  19. json_file = json.load(json_file)
  20. return cls(**json_file)
  21.  
  22. def printJson():
  23. print(test.cold_max)
  24. print(test.comfortable_min)
  25. print(test.comfortable_max)
  26. print(test.hot_min)
  27.  
  28. class Temperature:
  29. def __init__(self, temp):
  30. self.temp = sense.get_temperature()
  31.  
  32. def myfunc(self):
  33. print("Temperature: %s C" % self.temp)
  34. return temp
  35.  
  36.  
  37. """
  38. class Display:
  39. def __init__(self, display):
  40. self.temp = sense.get_temperature()
  41. sense.set_rotation(270)
  42.  
  43. def myfunc(self):
  44. sense.show_message("%.1f C" % self.temp, scroll_speed=0.10)
  45. """
  46.  
  47. class Led:
  48. def __init__(self, led):
  49. self.temp = sense.get_temperature()
  50.  
  51. def myfunc(self):
  52. if self.temp <= cold_min:
  53. print("Cold")
  54. #b = (0,0,255) #blue
  55. #sense.clear(b)
  56. #sense.set_pixels(led_blue)
  57. elif self.temp >= cold_max:
  58. print("Hot")
  59. #r = (255,0,0) #red
  60. #sense.clear(r)
  61. #sense.set_pixels(led_red)
  62. else:
  63. print("comfortable")
  64. #g = (0,255,0) #green
  65. #sense.clear(g)
  66. #sense.set_pixels(led_green)
  67.  
  68. test = TempRange.readJsonintoList(json_file)
  69. t1 = Temperature(sense)
  70. #t2 = Display(sense)
  71. t3 = Led(sense)
  72.  
  73. def main():
  74. while True:
  75.  
  76. t1 = Temperature(sense)
  77. #t2 = Display(sense)
  78. t3 = Led(sense)
  79.  
  80. t1.myfunc()
  81. t2.myfunc()
  82. t3.myfunc()
  83.  
  84. time.sleep(10)
  85.  
  86. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement