mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Update lis3dh.py
This commit is contained in:
parent
735cac7768
commit
c881e589fb
11
lis3dh.py
11
lis3dh.py
|
@ -59,18 +59,17 @@ class lis3dh:
|
|||
|
||||
def readAll(self) -> list:
|
||||
check_status = smbus2.i2c_msg.write(self.addr, [0x27])
|
||||
read_axis = smbus2.i2c_msg.read(self.addr, 1)
|
||||
x = smbus2.i2c_msg.read(self.addr, 1)
|
||||
y = smbus2.i2c_msg.read(self.addr, 1)
|
||||
z = smbus2.i2c_msg.read(self.addr, 1)
|
||||
prepare_x = smbus2.i2c_msg.write(self.addr, [0x28])
|
||||
prepare_y = smbus2.i2c_msg.write(self.addr, [0x2A])
|
||||
prepare_z = smbus2.i2c_msg.write(self.addr, [0x2C])
|
||||
read_status = smbus2.i2c_msg.read(self.addr, 1)
|
||||
status = self.i2c.i2c_rdwr(check_status, read_status)
|
||||
self.i2c.i2c_rdwr(check_status, read_status)
|
||||
#while status.buf[0] != 0b1111:
|
||||
# sleep(0.00001)
|
||||
print(status)
|
||||
x = self.i2c.i2c_rdwr(prepare_x, read_axis)
|
||||
y = self.i2c.i2c_rdwr(prepare_y, read_axis)
|
||||
z = self.i2c.i2c_rdwr(prepare_z, read_axis)
|
||||
self.i2c.i2c_rdwr(prepare_x, x, prepare_y, y, prepare_z, z)
|
||||
X = int.from_bytes(x.buf[0])
|
||||
Y = int.from_bytes(y.buf[0])
|
||||
Z = int.from_bytes(z.buf[0])
|
||||
|
|
Loading…
Reference in a new issue