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+ """Monitor pressure continuously and print an alert when pressure drops below a configurable threshold (e.g. storm detection)."""
2+
3+ from time import sleep
4+ from machine import I2C
5+ from wsen_pads import WSEN_PADS
6+ from wsen_pads .const import ODR_10_HZ
7+
8+ PRESSURE_ALERT_HPA = 1021.8 # Alert threshold
9+ READ_INTERVAL_S = 1 # Time between printed readings
10+
11+ i2c = I2C (1 )
12+ sensor = WSEN_PADS (i2c )
13+
14+ sensor .set_continuous (odr = ODR_10_HZ )
15+
16+ print ("Pressure monitor started" )
17+ print ("Alert threshold:" , PRESSURE_ALERT_HPA , "hPa" )
18+
19+ alert_active = False
20+
21+ while True :
22+ pressure = sensor .pressure_hpa ()
23+
24+ # Threshold detection
25+ if pressure < PRESSURE_ALERT_HPA :
26+ if not alert_active :
27+ print ("ALERT: pressure dropped below" , PRESSURE_ALERT_HPA , "hPa" )
28+ alert_active = True
29+ else :
30+ if alert_active :
31+ print ("INFO: pressure back above" , PRESSURE_ALERT_HPA , "hPa" )
32+ alert_active = False
33+
34+ sleep (READ_INTERVAL_S )
You can’t perform that action at this time.
0 commit comments