Created
October 28, 2018 21:30
-
-
Save vwillcox/592396cdfd0c910c36bb578d9b34d14b to your computer and use it in GitHub Desktop.
Take the LUX level and room temp from an Enviro Phat and show the room temp on a Scroll Phat HD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import numpy as np | |
import subprocess | |
from envirophat import weather, leds, light | |
import scrollphathd as sphd | |
from scrollphathd.fonts import font3x5 | |
sphd.clear() | |
sphd.show() | |
sphd.rotate(degrees=180) | |
def get_average(): | |
x = 0 | |
temp_calibrated_c = [] | |
while (x < 100): | |
temperature = round(weather.temperature(),2) | |
cpu_temp = subprocess.check_output("vcgencmd measure_temp", shell=True) | |
array = cpu_temp.split("=") | |
array2 = array[1].split("'") | |
cpu_tempc = float(array2[0]) | |
cpu_tempc = float("{0:.2f}".format(cpu_tempc)) | |
cpu_tempf = float(array2[0]) * 9.0 / 5.0 + 32.0 | |
cpu_tempf = float("{0:.2f}".format(cpu_tempf)) | |
temp_calibrated_c.append(temperature - ((cpu_tempc - temperature)/5.466)) | |
x = x + 1 | |
curTemp = np.mean(temp_calibrated_c) | |
return curTemp | |
try: | |
while True: | |
lux = light.light() | |
if lux > 10: | |
curTemp = str(get_average()) | |
sphd.write_string(curTemp, font=font3x5, brightness=0.5) | |
sphd.show() | |
time.sleep(5) | |
sphd.clear() | |
else: | |
sphd.clear() | |
sphd.show() | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment