From e32e5f93b3f263be0ef63bcf4d3f1095436f2e47 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sat, 26 Feb 2022 23:08:41 +0000 Subject: [PATCH] Update lis3dh.py --- lis3dh.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lis3dh.py b/lis3dh.py index 51df0c7..4a458a4 100644 --- a/lis3dh.py +++ b/lis3dh.py @@ -67,12 +67,14 @@ class lis3dh: prepare_z = smbus2.i2c_msg.write(self.addr, [0x2C]) status = smbus2.i2c_msg.read(self.addr, 1) self.i2c.i2c_rdwr(check_status, status) - #while status.buf[0] != 0b1111: - # sleep(0.00001) - self.i2c.i2c_rdwr(prepare_x, x) - self.i2c.i2c_rdwr(prepare_y, y) - self.i2c.i2c_rdwr(prepare_z, z) - X = int.from_bytes(x.buf[0],"big") - Y = int.from_bytes(y.buf[0],"big") - Z = int.from_bytes(z.buf[0],"big") - return [X,Y,Z] \ No newline at end of file + while status.buf[0] != 0b1111: + sleep(1) + self.i2c.i2c_rdwr(check_status, status) + if status.buf[0] == 0b1111: + self.i2c.i2c_rdwr(prepare_x, x) + self.i2c.i2c_rdwr(prepare_y, y) + self.i2c.i2c_rdwr(prepare_z, z) + X = int.from_bytes(x.buf[0],"big") + Y = int.from_bytes(y.buf[0],"big") + Z = int.from_bytes(z.buf[0],"big") + return [X,Y,Z] \ No newline at end of file