summaryrefslogtreecommitdiffstats
path: root/adxl.py
diff options
context:
space:
mode:
Diffstat (limited to 'adxl.py')
-rw-r--r--adxl.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/adxl.py b/adxl.py
index c5e5f61..c87781d 100644
--- a/adxl.py
+++ b/adxl.py
@@ -6,7 +6,6 @@ class ADXL():
def __init__(self, SCL, SDA):
self.SCL = SCL
self.SDA = SDA
-
self._i2c = machine.I2C(scl=self.SCL, sda=self.SDA, freq=100000)
self._last_x = 0.0
@@ -16,17 +15,18 @@ class ADXL():
self._last_act_y = 0.0
self._last_act_z = 0.0
+ self._is_active = False
+
self._timer = machine.Timer(-1)
self._timer.init(period=100, mode=machine.Timer.PERIODIC, callback=self._timer_cb)
- self._is_active = True
-
self._timer_cb(None)
def setup(self):
r = self._i2c.readfrom_mem(self.ADXL_ADDR, 0x2D, 1)
- if (not bool(r[0] & (1 << 3)) or True):
+ if (not bool(r[0] & (1 << 3))):
+ print('setup')
# OFFSET_{X,Y,Z}
#self._i2c.writeto_mem(self.ADXL_ADDR, 0x1E, bytes([25, 76, 183]))
self._i2c.writeto_mem(self.ADXL_ADDR, 0x1E, bytes([25, 75, 131]))
@@ -75,14 +75,14 @@ class ADXL():
def _timer_cb(self, t):
int_src = self._i2c.readfrom_mem(self.ADXL_ADDR, 0x30, 1)
- #print(int_src)
- #print(self.read_data())
if (bool(int_src[0] & (1 << 4))):
+ print('activity detected')
self._is_active = True
(self._last_act_x, self._last_act_y, self._last_act_z) = self.read_data()
if (bool(int_src[0] & (1 << 3))):
+ print('inactivity detected')
self._is_active = False
if (bool(int_src[0] & (1 << 7))):