from sense_hat import SenseHat

from time import sleep

sense = SenseHat ( )

sense. clear ( ) # clear display.

print ( "Temperature:" + str ( round ( sense. get_temperature ( ) , 1 ) ) )

print ( "Humidity:" + str ( round ( sense. get_humidity ( ) , 1 ) ) )

temperature = round ( sense. get_temperature ( ) )

humidity = round ( sense. get_humidity ( ) )

# print(temperature)

# 8 leds per bar, each led represents 1C

fullbars_t = int ( temperature/ 8 )

partbars_t = temperature- ( fullbars_t* 8 )

# 8 leds per bar, each led represents 1%

fullbars_h = int ( humidity/ 8 )

partbars_h = humidity- ( fullbars_h* 8 )

print ( "Amount of full bars T = " + str ( fullbars_t ) )

print ( "Amount of leds left T = " + str ( partbars_t ) )

print ( "Amount of full bars H% = " + str ( fullbars_h ) )

print ( "Amount of leds left H% = " + str ( partbars_h ) )

# resetting all values to 0

x = 0

y = 0

# set colours

g = 0

b = 0

if temperature < 50 : # We can't go over 255 as a value.

r = ( temperature* 5 )

print ( "red value: " + str ( r ) )

else :

r = 255

# The first part, we only display the full bars.

for x in range ( 0 , ( fullbars_t ) ) :

for y in range ( 0 , 8 ) :

sense. set_pixel ( ( x ) , ( y ) , ( r ) , ( g ) , ( b ) )

sleep ( 0.1 )

# Second part, we display the leftovers.

# We start our X axis on the spot after the last full bar.

# Remember: X and Y axis start at 0!!

for y in range ( 0 , partbars_t ) :

sense. set_pixel ( ( fullbars_t ) , ( y ) , ( r ) , ( g ) , ( b ) )

sleep ( 0.1 )

sleep ( 3 ) # Show for 3 seconds.

sense. clear ( ) # clear display.

# set colours

r = 0

g = 0

b = 0

if humidity < 50 : # We can't go over 255 as a value.

g = ( humidity* 5 )

print ( "green value: " + str ( g ) )

else :

g = 255

# The first part, we only display the full bars.

for x in range ( 0 , ( fullbars_h ) ) :

for y in range ( 0 , 8 ) :

sense. set_pixel ( ( x ) , ( y ) , ( r ) , ( g ) , ( b ) )

sleep ( 0.1 )

# Second part, we display the leftovers.

# We start our X axis on the spot after the last full bar.

# Remember: X and Y axis start at 0!!

for y in range ( 0 , partbars_h ) :

sense. set_pixel ( ( fullbars_h ) , ( y ) , ( r ) , ( g ) , ( b ) )

sleep ( 0.1 )

sleep ( 5 ) # Show for 5 seconds.