Skip to content

Commit 09db75f

Browse files
committed
added interrupt example
1 parent 62e856d commit 09db75f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/examples.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Ensure your device works with these simple tests.
77
:caption: examples/lsm303agr_mag_simpletest.py
88
:linenos:
99

10+
.. literalinclude:: ../examples/lsm303agr_mag_interrupt.py
11+
:caption: examples/lsm303agr_mag_interrupt.py
12+
:linenos:
13+
14+
examples/lsm303agr_mag_interrupt.py

examples/lsm303agr_mag_interrupt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
import board
3+
import busio
4+
import adafruit_lsm303agr_mag
5+
6+
i2c = busio.I2C(board.SCL, board.SDA)
7+
lsm_mag = adafruit_lsm303agr_mag.LSM303AGR_Mag(i2c)
8+
lsm_mag.interrupt_threshold = 80
9+
lsm_mag.interrupt_enabled = True
10+
11+
while True:
12+
x_hi, y_hi, z_hi, x_lo, y_lo, z_lo, int_triggered = lsm_mag.faults
13+
14+
print(lsm_mag.magnetic)
15+
print("Xhi:%s\tYhi:%s\tZhi:%s"%(x_hi, y_hi, z_hi))
16+
print("Xlo:%s\tYlo:%s\tZlo:%s"%(x_lo, y_lo, z_lo))
17+
print("Int triggered: %s"%int_triggered)
18+
print()
19+
20+
time.sleep(1)

0 commit comments

Comments
 (0)