TotteL

Untitled

Feb 1st, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import time
  2. from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
  3. import os
  4.  
  5. sense = SenseHat()
  6. sense.rotation = 180
  7. linebreak = "--------------"
  8.  
  9. def writfile():
  10.     file = open("tmp.txt", "a")
  11.     file.write((time.strftime("%d/%m/%Y - %H:%M:%S") + "\n"))
  12.     file.write(msgt + "\n")
  13.     file.write(msgp + "\n")
  14.     file.write(msgh + "\n")
  15.     file.write(linebreak + "\n")
  16.  
  17.  
  18. def consoleprint():
  19.     print(time.strftime("%d/%m/%Y - %H:%M:%S"))
  20.     print(msgt)
  21.     print(msgp)
  22.     print(msgh)
  23.     print(linebreak)
  24.  
  25.  
  26. def matrixprint():
  27.     sense.show_message(msgt, scroll_speed=0.08, back_colour=bg)
  28.     sense.load_image("space_invader.png")
  29.     time.sleep(1)
  30.     sense.show_message(msgp, scroll_speed=0.08, back_colour=bg)
  31.     sense.load_image("space_invader.png")
  32.     time.sleep(1)
  33.     sense.show_message(msgh, scroll_speed=0.08, back_colour=bg)
  34.     sense.load_image("space_invader.png")
  35.     time.sleep(1)
  36.  
  37.  
  38. while True:
  39.  
  40.     # Formula to get more accurate temp
  41.     temp = sense.get_temperature()
  42.     t = os.popen('/opt/vc/bin/vcgencmd measure_temp')
  43.     cputemp = t.read()
  44.     cputemp = cputemp.replace('temp=', '')
  45.     cputemp = cputemp.replace('\'C\n', '')
  46.     cputemp = float(cputemp)
  47.     newtemp = temp - ((cputemp - temp) / 2 )
  48.  
  49.     p = sense.get_pressure()
  50.     h = sense.get_humidity()
  51.  
  52.     p = round(p, 1)
  53.     h = round(h, 1)
  54.     newtemp = round(newtemp, 1)
  55.  
  56.     if newtemp > 18 and newtemp < 30: # Changes background color depending on degrees
  57.         bg = [0, 100, 0]  # green
  58.     elif newtemp < 10:
  59.         bg = [0, 0, 100]  # red
  60.     else:
  61.         bg = [100, 0, 0]
  62.  
  63.     msgt = "T: %sC" % (newtemp)
  64.     msgp = "P: %s hPa" % (p)
  65.     msgh = "H: %s%% rH" % (h)
  66.  
  67.     consoleprint()  # See function
  68.     writfile()  # See function
  69.     matrixprint()  # See function
Advertisement
Add Comment
Please, Sign In to add comment