Skip to content

Commit 972923b

Browse files
committed
examples: Add treshold_alert for wsen-pads.
1 parent 324c3ac commit 972923b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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)

0 commit comments

Comments
 (0)