File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from time import sleep
2+ from machine import I2C
3+ from wsen_pads import WSEN_PADS
4+ from wsen_pads .const import ODR_10_HZ
5+
6+ i2c = I2C (1 )
7+ sensor = WSEN_PADS (i2c )
8+
9+ sensor .set_continuous (odr = ODR_10_HZ )
10+
11+ pressure_history = []
12+ MAX_VALUES = 10
13+ THRESHOLD = 0.12 # sensitivity (hPa) ~ 1 meter altitude change
14+
15+ def get_trend (values ):
16+ if len (values ) < 2 :
17+ return "N/A"
18+
19+ diff = values [- 1 ] - values [0 ]
20+
21+ if abs (diff ) < THRESHOLD :
22+ return "stable"
23+ elif diff > 0 :
24+ return "falling" # pressure rising means lower altitude
25+ else :
26+ return "rising"
27+
28+ while True :
29+ pressure = sensor .pressure_hpa ()
30+
31+ # store value
32+ pressure_history .append (pressure )
33+
34+ # keep only last 10 values
35+ if len (pressure_history ) > MAX_VALUES :
36+ pressure_history .pop (0 )
37+
38+ trend = get_trend (pressure_history )
39+
40+ print ("P:" , pressure , "hPa Trend:" , trend )
41+
42+ sleep (10 )
You can’t perform that action at this time.
0 commit comments