Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sense_hat import SenseHat
- import time
- import json
- sense = SenseHat()
- json_file = []
- class TempRange(object):
- def __init__(self, cold_max, comfortable_min, comfortable_max, hot_min):
- self.cold_max = cold_max
- self.comfortable_min = comfortable_min
- self.comfortable_max = comfortable_max
- self.hot_min = hot_min
- @classmethod
- def readJsonintoList(cls, json_file):
- with open("config.json") as json_file:
- json_file = json.load(json_file)
- return cls(**json_file)
- def printJson():
- print(test.cold_max)
- print(test.comfortable_min)
- print(test.comfortable_max)
- print(test.hot_min)
- class Temperature:
- def __init__(self, temp):
- self.temp = sense.get_temperature()
- def myfunc(self):
- print("Temperature: %s C" % self.temp)
- return temp
- """
- class Display:
- def __init__(self, display):
- self.temp = sense.get_temperature()
- sense.set_rotation(270)
- def myfunc(self):
- sense.show_message("%.1f C" % self.temp, scroll_speed=0.10)
- """
- class Led:
- def __init__(self, led):
- self.temp = sense.get_temperature()
- def myfunc(self):
- if self.temp <= cold_min:
- print("Cold")
- #b = (0,0,255) #blue
- #sense.clear(b)
- #sense.set_pixels(led_blue)
- elif self.temp >= cold_max:
- print("Hot")
- #r = (255,0,0) #red
- #sense.clear(r)
- #sense.set_pixels(led_red)
- else:
- print("comfortable")
- #g = (0,255,0) #green
- #sense.clear(g)
- #sense.set_pixels(led_green)
- test = TempRange.readJsonintoList(json_file)
- t1 = Temperature(sense)
- #t2 = Display(sense)
- t3 = Led(sense)
- def main():
- while True:
- t1 = Temperature(sense)
- #t2 = Display(sense)
- t3 = Led(sense)
- t1.myfunc()
- t2.myfunc()
- t3.myfunc()
- time.sleep(10)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement