I know Celsius is a better way to display temperature, but unfortunately here in the US we don't "get it".
Is there a way to make the Sense Hat display Temperature in Fahrenheit ?
Code: Select all
temp = ((temp/5)*9)+32Code: Select all
def tofahrenheit(celsius):
return( (celsius/5*9)+32 )
temp = tofahrenheit(sense.get_temperature())
print(temp)
You most definitely can! Define "code"? What language?andyk1 wrote:Is there any way anyone can show me a line of code that uses this formula. I have searched and can not find a usable line of code for this. You can't just enter that into code and not run into errors.
Be sure that you use the correct IF..ELIF..ELSE syntax in python.andyk1 wrote: One other issue I am having is changing the color of the display... not background to a color say from:
-15 F to 65 F to be blue
66F to 85F to be green
86F to 120F to be red
On the sense-had display. I manage to get two colors to work, green and red but seems my code cancels out the colder blue code.
Code: Select all
if temp <= 65:
displayBlue()
elif temp > 65 and temp <=85 :
displayGreen()
else:
displayRed()
Code: Select all
# Project By Andy to create temp, hum, press, wind, rain, soil, uv , security cam's and other sensor.
from sense_hat import SenseHat
sense = SenseHat()
sense.set_rotation(180)
while True:
t = sense.get_temperature() * 9/5 + 32 # changed to Fahrenheit. Works
# t = sense.get_temperature() * 1.8 + 32; another way to read F temp
p = sense.get_pressure()
h = sense.get_humidity()
t = round(t, 1)
p = round(p, 1)
h = round(h, 1)
# if t > -15.0 and t < 64.9: # can't get to read
# tc = [0, 0, 100] # Blue
# else:
# tc = [0, 100, 0] # Green
if t > 65.0 and t < 84.9:
tc = [0, 100, 0] # Green
else:
tc = [100, 0, 0] # Red
# if h > 85.0 and h < 120.0: can't get to read
# tc = [100, 0, 0] # red
# else: can't get to read
# tc = [100, 0, 0] # red
# msg = "T={0} P={0} H={0}" .format ( t,p,h )
msg = "T=%s P=%s H=%s"% (t , p, h)
# sense.show_message(msg, scroll_speed=0.05, text_colour=[0,0,0], back_colour=bg)
sense.show_message(msg, scroll_speed=0.07, text_colour=tc) # bg=background color
# todo. setup other sensors
# todo. setup day-night brightness
# todo .setuo to show on monitor alsoI assume that should be t in the final commented out if statement, not h.andyk1 wrote:Code: Select all
# if t > -15.0 and t < 64.9: # can't get to read # tc = [0, 0, 100] # Blue # else: # tc = [0, 100, 0] # Green if t > 65.0 and t < 84.9: tc = [0, 100, 0] # Green else: tc = [100, 0, 0] # Red # if h > 85.0 and h < 120.0: can't get to read # tc = [100, 0, 0] # red # else: can't get to read # tc = [100, 0, 0] # red
Code: Select all
if -15 <= t <= 65:
tc = [0, 0, 100] # Blue
elif 65 < t <= 85:
tc = [0, 100, 0] # Green
elif 85 < t <= 120:
tc = [100, 0, 0] # Red
else:
tc = [100, 100, 100] # White
Code: Select all
if t <= 65:
tc = [0, 0, 100] # Blue
elif t <= 85:
tc = [0, 100, 0] # Green
else:
tc = [100, 0, 0] # Red
Code: Select all
if temperature < 65:
temp_background_colour = [0, 0, 100]
elif temperature > 85 :
temp_background_colour = [100, 0, 0]
else:
temp_background_colour = [0, 100, 0]Code: Select all
from sense_hat import SenseHat
sense = SenseHat()
sense.set_rotation(180)
while True:
t = sense.get_temperature() * 1.8 + 32;
p = sense.get_pressure()
h = sense.get_humidity()
t = round(t, 1)
p = round(p, 1)
h = round(h, 1)
if t <= 65:
tc = [0, 0, 100] # Blue
elif t <= 80:
tc = [0, 100, 0] # Green
else:
tc = [100, 0, 0] # Red
msg = "T=%s P=%s H=%s"% (t , p, h)
sense.show_message(msg, scroll_speed=0.07, text_colour=tc) # bc=background color
What about the print command doesn't work? Where do you expect the text to be displayed?andyk1 wrote: Can someone show me how to print this to the monitor and sense-hat at the same time please? The print command doesn't work for me.
I am using IDLE 3 Python 3.What about the print command doesn't work? Where do you expect the text to be displayed?
Are you running your program from the command line or from an IDE like IDLE?