Skip to content

Commit

Permalink
Merge pull request #793 from awjlogan/enviro-tidy
Browse files Browse the repository at this point in the history
Enviro Pico description generation did not match f-string rounding
  • Loading branch information
Gadgetoid authored Aug 4, 2023
2 parents e1527c4 + 1e6e683 commit d93839d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions micropython/examples/pico_enviro/enviro_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def adjust_to_sea_pressure(pressure_hpa, temperature, altitude):

def describe_pressure(pressure_hpa):
"""Convert pressure into barometer-type description."""
pressure_hpa += 0.5
if pressure_hpa < 970:
description = "storm"
elif 970 <= pressure_hpa < 990:
Expand All @@ -80,6 +81,7 @@ def describe_pressure(pressure_hpa):

def describe_humidity(corrected_humidity):
"""Convert relative humidity into good/bad description."""
corrected_humidity += 0.5
if 40 < corrected_humidity < 60:
description = "good"
else:
Expand All @@ -89,6 +91,7 @@ def describe_humidity(corrected_humidity):

def describe_light(lux):
"""Convert light level in lux to descriptive value."""
lux += 0.5
if lux < 50:
description = "dark"
elif 50 <= lux < 100:
Expand Down Expand Up @@ -186,7 +189,7 @@ def draw_hist(results_array):
time.sleep(0.5)

while True:
# turn off the backlight with A and turn it back on with B
# turn on the backlight with A and turn it back off with B
# switch between sensor and equaliser mode with X and Y
if button_a.is_pressed:
display.set_backlight(BRIGHTNESS)
Expand Down Expand Up @@ -263,7 +266,7 @@ def draw_hist(results_array):
display.set_pen(RED)
if corrected_temperature < 10:
display.set_pen(CYAN)
display.text(f"{corrected_temperature:.1f}°c", 5, 15, WIDTH, scale=4)
display.text(f"{corrected_temperature:.1f}°C", 5, 15, WIDTH, scale=4)

# draw temp max and min
display.set_pen(CYAN)
Expand All @@ -275,7 +278,7 @@ def draw_hist(results_array):
display.set_pen(WHITE)
display.text(f"rh {corrected_humidity:.0f}%", 0, 75, WIDTH, scale=3)
display.text(f"{pressure_hpa:.0f}hPa", 0, 125, WIDTH, scale=3)
display.text(f"{lux} lux", 0, 175, WIDTH, scale=3)
display.text(f"{lux:.0f} lux", 0, 175, WIDTH, scale=3)

# draw the second column of text
display.text(f"{describe_humidity(corrected_humidity)}", 125, 75, WIDTH, scale=3)
Expand Down

0 comments on commit d93839d

Please sign in to comment.