Skip to content

Commit

Permalink
Merge pull request #491 from adriangalilea/main
Browse files Browse the repository at this point in the history
Add adjust_to_sea_pressure function
  • Loading branch information
Gadgetoid authored Oct 6, 2022
2 parents 9878e4b + 3cfac27 commit 8280a6a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions micropython/examples/pico_enviro/enviro_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

BRIGHTNESS = 0.8

# change this to adjust pressure based on your altitude
altitude = 0

# light the LED red if the gas reading is less than 50%
GAS_ALERT = 0.5

Expand All @@ -46,6 +49,18 @@ def graphic_equaliser():
led.set_rgb(0, ms, 0)


def adjust_to_sea_pressure(pressure_hpa, temperature, altitude):
"""
Adjust pressure based on your altitude.
credits to @cubapp https://gist.github.com/cubapp/23dd4e91814a995b8ff06f406679abcf
"""

# Adjusted-to-the-sea barometric pressure
adjusted_hpa = pressure_hpa + ((pressure_hpa * 9.80665 * altitude) / (287 * (273 + temperature + (altitude / 400))))
return adjusted_hpa


def describe_pressure(pressure_hpa):
"""Convert pressure into barometer-type description."""
if pressure_hpa < 970:
Expand Down Expand Up @@ -213,6 +228,9 @@ def draw_hist(results_array):
# convert pressure into hpa
pressure_hpa = pressure / 100

# correct pressure
pressure_hpa = adjust_to_sea_pressure(pressure_hpa, corrected_temperature, altitude)

# read LTR559
ltr_reading = ltr.get_reading()
lux = ltr_reading[BreakoutLTR559.LUX]
Expand Down

0 comments on commit 8280a6a

Please sign in to comment.